memory-orm
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Mem=e():t.Mem=e()}(global,function(){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=5)}([function(t,e){t.exports=require("lodash")},function(t,e,r){"use strict";var i,n,s,o,a,u,l,c,h,f,p,d,m,y,_,$;m=r(0),s=r(3),p={},u={},c={},f={},o={},i=[],n=0,h=function(){return Object.create(null)},l=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),null==t.pack&&(t.pack=h()),t}json(){return JSON.stringify(this,(t,e)=>{var r,i;return e&&e.meta&&e.item&&e.$group&&e.meta===this?(({item:i,$group:r}=e),{item:i,$group:r}):e})}},a=function(t={}){return l.bless(t),t},$=function(){return++n},d={transaction:function(t,e){var r;return this.$journal=r=a(e),t(e),this.$journal=a(),r},journal:(y=function(t){return function(e){var r,i;return(r=d[t].pack)[e]?r[e]:((i=r[e]=h()).$sort=h(),i.$memory=h(),i.$format=h(),i)}})("$journal"),base:y("$base"),meta:function(){return this.$journal},step:h(),$journal:a(),$base:a(),store:function(t){var e,r,i,n,a,u,l,c,h,f,p;if(!(null!=t?t.pack:void 0))return!1;for(c in p=t.pack)if(({$sort:i,$memory:r,$format:e}=p[c]),a=o[c]){for(l in({model:h}=a),n=this.base(c),u=this.journal(c),i)f=i[l],n.$sort[l]=f,u.$sort[l]=f;for(l in e)f=e[l],n.$format[l]=f,u.$format[l]=f;for(l in r)f=r[l],s.bless(f,t,h),n.$memory[l]=f,u.$memory[l]=f;a.clear_cache()}else console.error("not found Finder and Query",c,t.pack);return!0},mixin:{data:function(){return{$step:d.step}}},join:function({react:t}){t&&i.push(t)},bye:function({react:t}){t&&(i=i.filter(function(e){return e!==t}))},notify:function(t){if(this.step[t]=$(),i.length)return this.notify_for_react()},notify_for_react:m.debounce(function(){var t,e,r,n,s,o,a,u,l,c;for(l=[],r=0,s=i.length;r<s;r++){for(n in e={},t=!1,u=(a=i[r]).state)u[n],"step_"===n.slice(0,5)&&(o=n.slice(5),c=this.step[o],a.state[n]<c&&(e[n]=c,t=!0));t?l.push(a.setState(e)):l.push(void 0)}return l},1)},_=function(t){var e,r,i;for(e in r=[],t)switch(i=t[e],!1){case null==f[e]:e=c[e].base,r.push(p[e].merge(i));break;case null==p[e]:r.push(p[e].append(i));break;default:r.push(void 0)}return r},t.exports={Set:p,Map:u,Name:c,State:d,Finder:o,Query:f,PureObject:h,merge:_,step:$}},function(t,e,r){"use strict";var i,n,s,o,a=[].splice;n=r(0),o=function(t){var e,r,i;for(i={},Reflect.setPrototypeOf(i,null),e=0,r=t.length;e<r;e++)i[t[e]]=!0;return i},s=function(t,e,r){return e?new i(t,function(){var i,s,o;switch(this._filters=t._filters.concat(),e&&e.constructor){case Object:for(i in s=[],e)o=e[i],s.push(r(this,i,o,n.property(i)));return s;case Function:case Array:case String:return r(this,null,e,function(t){return t});default:return console.log({req:e})}}):t},t.exports=i=function(){class t{static build({$sort:e,$memory:r}){var i;return i=null,new t({_all_ids:i,_group:null,_filters:[],$sort:e,$partition:["set"]},function(){return this.all=this,this.$memory=r})}constructor(t,e){this._step=0,this._copy(t),e.call(this)}_copy({all:t,_all_ids:e,_group:r,_filters:i,$sort:n,$partition:s,$page_by:o}){this.all=t,this._all_ids=e,this._group=r,this._filters=i,this.$sort=n,this.$partition=s,this.$page_by=o}in(t){return s(this,t,function(t,e,r,i){var n,s,a;switch(n=function(e){return t._filters.push(e)},null!=(s=null!=r?r.constructor:void 0)?s:r){case Array:return a=o(r),n(function(t){var e,r,n,s;for(e=0,n=(s=i(t)).length;e<n;e++)if(r=s[e],a[r])return!0;return!1});case RegExp:return n(function(t){var e,n,s,o;for(e=0,n=(s=i(t)).length;e<n;e++)if(o=s[e],r.test(o))return!0;return!1});case null:case 0:case"":case Boolean:case String:case Number:return n(function(t){var e;return-1<(null!=(e=i(t))?e.indexOf(r):void 0)});default:throw console.log({target:e,req:[r,null!=r?r.constructor:void 0]}),Error("unimplemented")}})}partition(...e){return new t(this,function(){return this.$partition=e})}where(t){return s(this,t,function(t,e,r,i){var n,s,a;switch(n=function(e){return t._filters.push(e)},null!=(s=null!=r?r.constructor:void 0)?s:r){case Function:return n(r);case Array:return"_id"===e?t._all_ids=r:(a=o(r),n(function(t){return a[i(t)]}));case RegExp:return n(function(t){return r.test(i(t))});case null:case 0:case"":case Boolean:case String:case Number:return"_id"===e?t._all_ids=[r]:n(function(t){return r===i(t)});default:throw console.log({target:e,req:[r,null!=r?r.constructor:void 0]}),Error("unimplemented")}})}search(t){var e,r,i;return t&&(r=function(){var r,i,n,s;for(s=[],r=0,i=(n=t.split(/\s+/)).length;r<i;r++)(e=(e=n[r]).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")).length&&s.push(`(${e})`);return s}()).length?(i=new RegExp(r.join("|"),"ig"),this.where(function(t){var e;return!(e=t.q.search_words)||i.test(e)})):this}shuffle(){return this.sort(Math.random)}order(...e){var r,i,s;return s=e,[...e]=s,[r]=a.call(e,-1),e.length||e.push("list"),i=["_reduce",...e].join("."),n.isEqual(r,this.$sort[i])?this:new t(this,function(){return this.$sort=n.cloneDeep(this.$sort),this.$sort[i]=r})}sort(...t){return this.order({sort:t})}page(e){return new t(this,function(){return this.$page_by=e})}form(...t){var e,r,i;return(i=this.find(...t))?(r=null!=(e=this.all.$memory[i.id]).form?e.form:e.form={},Reflect.setPrototypeOf(r,i),r):i}find(...t){var e,r,i,n;for(e=0,i=t.length;e<i;e++)if(r=t[e],n=this.hash[r])return n;return null}finds(t){var e,r,i,n,s;for(s=[],e=0,i=t.length;e<i;e++)r=t[e],(n=this.hash[r])&&s.push(n);return s}pluck(){return this.list.pluck(...arguments)}}return Object.defineProperties(t.prototype,{reduce:{get:function(){return this.all._finder.calculate(this,this.all.$memory),this._reduce}},list:{get:function(){return this.reduce.list}},hash:{get:function(){return this.reduce.hash}},memory:{get:function(){return this.all.$memory}},ids:{get:function(){return Object.keys(this.hash)}}}),t}.call(void 0)},function(t,e,r){"use strict";t.exports=class{static bless(t,e,r){return r.bless(t.item),t.meta=e}constructor(t,e){this.meta=t,this.item=e,this.$group=[]}toJSON(t){return{item:this.item,$group:this.$group}}}},function(t,e,r){"use strict";t.exports={Query:r(2),Set:r(7),Map:r(8),List:r(9),Model:r(10),Finder:r(11)}},function(t,e,r){"use strict";var i;t.exports=i=r(1),i.Rule=r(6),i.Base=r(4)},function(t,e,r){"use strict";var i,n,s,o,a,u,l,c,h,f=[].indexOf;c=r(0),o=r(1),({Finder:i,Query:u,Model:a,List:n,Set:l,Map:s}=r(4)),h=function(t){var e,r,i;return t=c.snakeCase(t).replace(/s$/,""),(r=o.Name[t])?r:(e=`${t}s`,o.Name[e]=o.Name[t]=i=o.PureObject(),i.base=t,i.list=e,i.id=`${t}_id`,i.ids=`${t}_ids`,i.deploys=[],i.depends=[],i)},t.exports=class{constructor(t,e){this.$name=h(t),this.state=o.State.base(this.$name.list),this.model=a,this.list=n,this.set=l,this.map=s,this.all=u.build(this.state),this.all.$sort["_reduce.list"]={},this.all._cache={},this.all._finder=new i(this.$name,this.state),this.depend_on(this.$name.list),this.map_property={},({base:t}=this.$name),this.model_property={id:{enumerable:!0,get:function(){return this._id}},[this.$name.id]:{enumerable:!0,get:function(){return this._id}}},this.form_property={changes:{enumerable:!0,value:function(t){return c.isEqual(this[t],this.find[t])?null:this.$model[t]}},isChanged:{enumerable:!0,get:function(){var t,e,r,i;for(t=0,i=(r=Object.keys(this)).length;t<i;t++)if(e=r[t],!c.isEqual(this[e],this.$model[e]))return!0;return!1}}},this.list_property={first:{enumerable:!1,get:function(){return this[0]}},head:{enumerable:!1,get:function(){return this[0]}},tail:{enumerable:!1,get:function(){return this[this.length-1]}},last:{enumerable:!1,get:function(){return this[this.length-1]}},uniq:{enumerable:!1,get:function(){return this.constructor.bless(c.uniq(this))}},pluck:{enumerable:!1,value:function(...t){return e=function(){switch(t.length){case 0:return function(){return null};case 1:return c.property(t[0]);default:return function(e){return c.at(e,...t)}}}(),this.constructor.bless(this.map(e))}}},this.set_property={},e&&this.schema(e)}schema(t){return t.call(this),this.model===a&&(this.model=class extends this.model{}),Object.defineProperties(this.model.prototype,this.model_property),this.list===n&&(this.list=class extends this.list{}),Object.defineProperties(this.list.prototype,this.list_property),this.set===l&&(this.set=class extends this.set{}),Object.defineProperties(this.set.prototype,this.set_property),this.map===s&&(this.map=class extends this.map{}),Object.defineProperties(this.map.prototype,this.map_property),this.model.$name=this.list.$name=this.set.$name=this.map.$name=this.$name,this.all._finder.deploy(this),o.Set[this.$name.base]=new this.set(this),o.Query[this.$name.list]=this.all,o.Finder[this.$name.list]=this.all._finder,this}key_by(t){var e;return e=function(){switch(null!=t?t.constructor:void 0){case void 0:return function(){return this._id};case Function:return t;case String:case Array:return c.property(t);default:throw Error(`unimplemented ${t}`)}}(),this.model_property.id={enumerable:!0,get:e}}deploy(t){return this.$name.deploys.push(t)}depend_on(t){return o.Name[t].depends.push(t)}scope(t){var e,r,i,n;for(e in i=[],r=t(this.all))n=r[e],i.push(this.use_cache(e,n));return i}property(t,e){return Object.assign(this[`${t}_property`],e)}default_scope(t){return this.all._copy(t(this.all)),o.State.base(this.$name.list).$sort=this.all.$sort}shuffle(){return this.default_scope(function(t){return t.shuffle()})}sort(...t){return this.default_scope(function(e){return e.sort(...t)})}order(...t){return this.default_scope(function(e){return e.order(...t)})}relation_to_one(t,e,r,i){return this.model_property[t]={enumerable:!0,get:function(){var t;return t=c.get(this,r),o.Query[e].find(t,i)}}}relation_to_many(t,e,r,i,n){var s;return s=this.all,this.use_cache(t,function(t){return o.Query[e][i]({[`${n}`]:t})}),this.model_property[t]={enumerable:!0,get:function(){return s[t](this[r])}}}relation_tree(t,e){var r;return r=this.all,this.use_cache(t,function(i,n){var s;return n?(s=r.where({[`${e}`]:i}),r[t](s.ids,n-1)):r.where({id:i})}),this.model_property[t]={enumerable:!0,value:function(e){return r[t]([this.id],e)}}}relation_graph(t,e){var r;return r=this.all,this.use_cache(t,function(i,n){var s,o,a,u,l,h,f,p,d;if(p=r.where({id:i}),n){for(a=[],o=0,h=(d=p.pluck(e)).length;o<h;o++)if(null!=(s=d[o]))for(u=0,f=s.length;u<f;u++)null!=(l=s[u])&&a.push(l);return r[t](c.uniq(a),n-1)}return p}),this.model_property[t]={enumerable:!0,value:function(e){return r[t]([this.id],e)}}}use_cache(t,e){switch(null!=e?e.constructor:void 0){case Function:return this.all[t]=((...r)=>{var i,n;return null!=(i=this.all._cache)[n=`${t}:${JSON.stringify(r)}`]?i[n]:i[n]=e(...r)});default:return this.all[t]=e}}path(...t){var e,r,i,n,s;for(r=0,n=t.length;r<n;r++)i=t[r],this.belongs_to(i);return this.deploy(function(){var e,r,n,s,o;for(o=this.id.split("-"),this.idx=o[t.length],s=[],e=r=0,n=t.length;r<n;e=++r)i=t[e],s.push(this[`${i}_id`]=o.slice(0,+e+1||9e9).join("-"));return s}),({all:e}=this),s=t.slice(-1)[0]+"_id",this.model_property.siblings={get:function(){var t;return(t={})[s]=this[s],e.where(t)}}}belongs_to(t,e={}){var r,i,n,s;return n=h(t),({key:r=n.id,target:s=n.list,miss:i}=e),this.relation_to_one(n.base,s,r,i)}habtm(t,e={}){var r,i,n;return i=h(t),e.reverse?(({key:r=this.$name.ids,target:n=t}=e),this.relation_to_many(i.list,n,"id","in",r)):(({key:r=i.ids,target:n=i.list}=e),this.relation_to_many(i.list,n,r,"where","id"))}has_many(t,e={}){var r,i,n;return i=h(t),({key:r=this.$name.id,target:n=i.list}=e),this.relation_to_many(i.list,n,"id","where",r)}tree(t={}){var e;return e=this.$name.id,this.relation_tree("nodes",e),this.belongs_to(this.$name.base,t),Object.defineProperties(this.all,{leaf:{get:function(){var t;return t=c.uniq(this.pluck(e)),this.where(function(e){var r;return r=e.id,f.call(t,r)<0})}}})}graph(t={}){var e,r,i;if(({directed:r,cost:e}=t),i=this.$name.ids,this.relation_to_many(this.$name.list,this.$name.list,i,"where","id"),this.relation_graph("path",i),!r)return!0}}},function(t,e,r){"use strict";var i,n,s,o,a,u;r(0),({State:n,Set:i}=r(1)),r(2),o=function(t){return function(e,r){var i,s,o;return o=n.meta(),i=n.base(this.$name.list),s=n.journal(this.$name.list),this.all._finder[t](o,i,s,this.all,e,r)}},u=function(t,e){var r,i,s;if(s=n.meta(),r=n.base(this.$name.list),i=n.journal(this.$name.list),null!=e)return this.all._finder.update(s,r,i,this.all,t,e)},a=function(t){return function(e,r){if(null!=e)return t.call(this,[e],r)}},s=function(){return this.all._finder.clear_cach()},t.exports=i=function(){class t{constructor({all:t,model:e,$name:r}){this.all=t,this.model=e,this.$name=r}find(...t){var e,r,i,s,o,a;for(o=n.meta(),i=n.journal(this.$name.list),e=0,s=t.length;e<s;e++)if(r=t[e],a=this.all.$memory[r])return a.meta=o,i.$memory[r]=a,this.all._finder.clear_cache(),a.item;return null}}return t.prototype.set=o("reset"),t.prototype.reset=o("reset"),t.prototype.merge=o("merge"),t.prototype.add=a(o("merge")),t.prototype.append=a(o("merge")),t.prototype.reject=o("remove"),t.prototype.del=a(o("remove")),t.prototype.remove=a(o("remove")),t.prototype.updates=u,t.prototype.update=a(u),t.prototype.clear_cache=s,t.prototype.refresh=s,t.prototype.rehash=s,t}.call(void 0)},function(t,e,r){"use strict";var i,n,s,o,a,u=[].splice;a=r(0),({State:o,Query:s}=r(1)),n=r(3),i=function(t,e){return Object.defineProperties(t,{_diff:{enumerable:!1,writable:!0,value:null},diff:{enumerable:!1,get:function(){var t,r,n,s,o;return this._diff?this._diff:(this._diff=function(){var i,u,l,c,h;for(h=[],n=i=0,c=this.length-2;0<=c?i<=c:i>=c;n=0<=c?++i:--i){for(t=this[n],r=this[n+1],o={},u=0,l=e.length;u<l;u++)s=e[u],a.set(o,s,a.get(r,s)-a.get(t,s));h.push(o)}return h}.call(this),i(this._diff,e))}}}),t},t.exports=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),t}static $deploy(t,e,r,i,s,o){var a;return a=new n(i,o),this.$deploy_reduce(t,o,e,s,a),this.$deploy_sort(t,o,r,s),a}static $deploy_reduce(t,e,r,i,n){var s,o,a;if(s=o=function(t,r){var i;return t.length?r:(s=function(t,e){return e},i={set:e.id,list:!0},Object.assign(i,r))},a=(t=>(...e)=>{var n,o,a,l,c,h;return h=e,[...e]=h,[o]=u.call(e,-1),o=s(e,o),c=["_reduce",...e].join("."),t.push([c,o]),a=null!=r[c]?r[c]:r[c]={},l=null!=(n=i.$format)[c]?n[c]:n[c]={},this.init(a,o),this.init(l,o)})(n.$group),t.map_partition(e,a),t.map_reduce(e,a),s===o)return a({})}static $deploy_sort(t,e,r,i){var n;return n=function(...t){var e,n,s;return s=t,[...t]=s,[e]=u.call(t,-1),n=["_reduce",...t].join("."),r[n]=e,i.$sort[n]=e},t.order(e,n)}static init(t,e){if(e.id&&(t.id=e.id),e.list&&(t.list=[]),e.count&&(t.count=0),e.all&&(t.all=0),e.set)return t.hash={}}static reduce(t,e,r,i,n){if(i)return n.count&&(i.count+=n.count),n.all&&(i.all+=n.all),n.pow&&(i.pow*=n.pow),n.list&&i.list.push(r),n.set&&(i.hash[n.set]=r),n.max&&(n.max<=i.max||(i.max_is=r,i.max=n.max)),!n.min||i.min<=n.min?void 0:(i.min_is=r,i.min=n.min);console.error("not found $format",e,n,t,r)}static finish(t,e,r,i){if(r)return r.hash&&(r.set=Object.keys(r.hash)),r.count&&null!=r.pow&&(r.avg=Math.pow(r.all,1/r.count)),r.count&&null!=r.all&&(r.avg=r.all*(1/r.count)),null!=r.min&&null!=r.max&&(r.range=r.max-r.min,r.all)?r.density=r.all/r.range:void 0;console.error("not found $format",e,t,i)}static order(t,e,r,i,n){var o,u,l,c,h,f,p,d,m,y,_;if(m=r,i.belongs_to)if(m instanceof Array)for(c=0,d=m.length;c<d;c++)_=m[c],Reflect.setPrototypeOf(_,s[i.belongs_to].find(_.id));else for(h in m)_=m[h],Reflect.setPrototypeOf(_,s[i.belongs_to].find(h));else if(m.constructor===Object)for(h in m)(_=m[h]).id=h;if(i.sort&&(m=a.orderBy(m,...i.sort)),i.pluck&&(m=function(){var t,e,r;for(r=[],t=0,e=m.length;t<e;t++)y=m[t],(_=a.get(y,i.pluck))&&r.push(_);return r}()),p=i.index){for(o in m){y=m[o],l="number"==typeof a.get(y,p)?[]:{};break}for(o in m)y=m[o],l[f=a.get(y,p)]||(l[f]=u=new n(t)),u.push(y);m=l}return m}static dash(t,e,r,n,s){var o,a;if(r instanceof Array)return a=r,(o=n.diff)&&(a=i(a,o)),a}static post_proc(t,e,r,i,n){var s,o,a,u,l,c,h,f,p,d,m,y,_;if(p=r,i.cover){for(_=[],o=[],a=0,h=(y=i.cover).length;a<h;a++)r[u=y[a]]?o.push(u):_.push(u);p.remain=_,p.cover=o}if(i.page&&(m=t.$page_by)){for((p=[]).all=r.length,l=c=0,f=r.length;c<f;l=++c)d=r[l],l%m||p.push(s=new n(t)),s.push(d);p.page_idx=function(t){var e,r,i;for(this,i=e=0,r=this.length;e<r;i=++e)if(this[i].includes(t))return i;return null}}return p}}},function(t,e,r){"use strict";var i;i=r(0),r(1),r(2),t.exports=class extends Array{static bless(t,e){return Reflect.setPrototypeOf(t,this.prototype),t.query=e,t}constructor(t){super(),this.query=t}sort(...t){var e;return e=i.orderBy(this,...t),Reflect.setPrototypeOf(e,Reflect.getPrototypeOf(this)),e}group_by(t){var e,r,n;for(e in r=i.groupBy(this,t))n=r[e],Reflect.setPrototypeOf(n,Reflect.getPrototypeOf(this));return r}page_by(t){var e;return e=0,Object.values(this.group_by(function(r){return Math.floor(e++/t)}))}where(t){return this.query.where(t)}in(t){return this.query.in(t)}}},function(t,e,r){"use strict";var i;i=r(0),t.exports=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),t}static $deploy(t,e){var r,n,s;for(this.bless(t),e&&i.merge(t,e),r=0,n=(s=this.$name.deploys).length;r<n;r++)s[r].call(t,this);if(!t.id)throw new Error(`detect bad data: ${JSON.stringify(t)}`)}static update(t,e){}static create(t){}static delete(t){}static map_partition(t,e){}static map_reduce(t,e){}static order(t,e){}}},function(t,e,r){"use strict";var i,n,s,o,a,u,l,c,h,f;u=r(0),({Finder:i,State:a,Query:o,Format:n,PureObject:s,step:h}=r(1)),c=function({list:t},e,r){var i,n,s;switch(null!=e?e.constructor:void 0){case Array:for(i=0,s=e.length;i<s;i++)r((n=e[i]).id||n)}},l=function({list:t},e,r){var i,n,s,o;switch(null!=e?e.constructor:void 0){case Array:for(i=0,o=e.length;i<o;i++)r(s=e[i]);break;case Object:for(n in e)(s=e[n])._id=n,r(s)}},f=function(t,e,r){var i,n;if(!t||!r)return!1;for(i=0,n=r.length;i<n;i++)if(!(0,r[i])(t,e))return!1;return!0},t.exports=i=class{constructor(t,{$format:e}){this.$name=t,this.$format=e,a.notify(this.$name.list)}deploy({set:t,map:e,list:r,model:i}){this.set=t,this.map=e,this.list=r,this.model=i}calculate(t,e){var r,i,n,s,o,l;if(t._step<a.step[this.$name.list]){if(delete t._reduce,t._step=h(),r=u.cloneDeep(this.$format),o={_reduce:{list:[],hash:{}}},t._all_ids)this.reduce(this.map,r,o,t,e,t._all_ids);else if(t===t.all)this.reduce(this.map,r,o,t,e,Object.keys(e));else for(i=0,n=(l=t.$partition).length;i<n;i++)s=l[i],this.reduce(this.map,r,o,t,e,u.get(t.all,`reduce.${s}`));this.finish(this.map,r,o,t)}}reduce(t,e,r,i,n,s){var o,a,u,l,c,h,p,d,m,y;if(s){for(y=[],u=0,h=s.length;u<h;u++)l=s[u],(d=n[l])&&(({meta:p,item:c,$group:o}=d),f(c,p,i._filters)&&y.push(function(){var n,s,u;for(u=[],n=0,s=o.length;n<s;n++)[m,a]=o[n],d=r[m]=e[m],u.push(t.reduce(i,m,c,d,a));return u}()));return y}}finish(t,e,r,i){var n,s,o,a,l,c,h,f,p;for(l in r)a=r[l],t.finish(i,l,a,this.list),u.set(i,l,a);for(l in f=[],c=i.$sort)n=c[l],(o=u.get(i,l))&&(p=t.order(i,l,o,n,this.list),s=t.dash(i,l,p,n,this.list),h=t.post_proc(i,l,s,n,this.list),this.list.bless(h,i),h.from=o,f.push(u.set(i,l,h)));return f}clear_cache(t=!0){var e,r,i,n;if(null!=t)for(e=0,r=(n=this.$name.depends).length;e<r;e++)i=n[e],a.notify(i)}reset(t,e,r,i,n,o){var a,u,l,c;for(a in r.$memory=s(),e.$memory=i.$memory=u=s(),this.merge(t,e,r,i,n,o),c=e.$memory)l=c[a],null==u[a]&&this.model.delete(l);return this.clear_cache(!0)}merge(t,e,r,i,n,s){var o;return o=!1,l(this.$name,n,n=>{var a,u;return u=e.$memory[n.id],this.model.$deploy(n,s),a=this.map.$deploy(this.model,this.$format,i.$sort,t,r,n),r.$memory[n.id]=a,e.$memory[n.id]=a,null!=u?this.model.update(n,u.item):this.model.create(n),o=!0}),this.clear_cache(o)}remove(t,e,r,i,n){var s;return s=!1,c(this.$name,n,t=>{var i;if(null!=(i=e.$memory[t]))return this.model.delete(i.item),delete r.$memory[t],delete e.$memory[t],s=!0}),this.clear_cache(s)}update(t,e,r,i,n,s){var o,a;return({$memory:o}=i),a=!1,c(this.$name,n,n=>{var o,l;if(l=e.$memory[n])return u.merge(l.item,s),o=this.map.$deploy(this.model,this.$format,i.$sort,t,r,l.item),r.$memory[n]=o,e.$memory[n]=o,this.model.update(l.item,l.item),a=!0}),this.clear_cache(a)}}}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.Mem=e():t.Mem=e()}(global,function(){return function(t){var e={};function r(i){if(e[i])return e[i].exports;var n=e[i]={i:i,l:!1,exports:{}};return t[i].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=t,r.c=e,r.d=function(t,e,i){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:i})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var i=Object.create(null);if(r.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var n in t)r.d(i,n,function(e){return t[e]}.bind(null,n));return i},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=5)}([function(t,e){t.exports=require("lodash")},function(t,e,r){"use strict";var i,n,s,o,a,u,l,h,c,f,p,d,m,y,_,g;m=r(0),s=r(3),p={},u={},h={},f={},o={},i=[],n=0,c=function(){return Object.create(null)},l=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),null==t.pack&&(t.pack=c()),t}json(){return JSON.stringify(this,(t,e)=>{var r,i;return e&&e.meta&&e.item&&e.$group&&e.meta===this?(({item:i,$group:r}=e),{item:i,$group:r}):e})}},a=function(t={}){return l.bless(t),t},g=function(){return++n},d={transaction:function(t,e){var r;return this.$journal=r=a(e),t(e),this.$journal=a(),r},journal:(y=function(t){return function(e){var r,i;return(r=d[t].pack)[e]?r[e]:((i=r[e]=c()).$sort=c(),i.$memory=c(),i.$format=c(),i)}})("$journal"),base:y("$base"),meta:function(){return this.$journal},step:c(),$journal:a(),$base:a(),store:function(t){var e,r,i,n,a,u,l,h,c,f,p;if(!(null!=t?t.pack:void 0))return!1;for(h in p=t.pack)if(({$sort:i,$memory:r,$format:e}=p[h]),a=o[h]){for(l in({model:c}=a),n=this.base(h),u=this.journal(h),i)f=i[l],n.$sort[l]=f,u.$sort[l]=f;for(l in e)f=e[l],n.$format[l]=f,u.$format[l]=f;for(l in r)f=r[l],s.bless(f,t,c),n.$memory[l]=f,u.$memory[l]=f;a.clear_cache()}else console.error("not found Finder and Query",h,t.pack);return!0},mixin:{data:function(){return{$step:d.step}}},join:function({react:t}){t&&i.push(t)},bye:function({react:t}){t&&(i=i.filter(function(e){return e!==t}))},notify:function(t){if(this.step[t]=g(),i.length)return this.notify_for_react()},notify_for_react:m.debounce(function(){var t,e,r,n,s,o,a,u,l,h;for(l=[],r=0,s=i.length;r<s;r++){for(n in e={},t=!1,u=(a=i[r]).state)u[n],"step_"===n.slice(0,5)&&(o=n.slice(5),h=this.step[o],a.state[n]<h&&(e[n]=h,t=!0));t?l.push(a.setState(e)):l.push(void 0)}return l},1)},_=function(t){var e,r,i;for(e in r=[],t)switch(i=t[e],!1){case null==f[e]:e=h[e].base,r.push(p[e].merge(i));break;case null==p[e]:r.push(p[e].append(i));break;default:r.push(void 0)}return r},t.exports={Set:p,Map:u,Name:h,State:d,Finder:o,Query:f,PureObject:c,merge:_,step:g}},function(t,e,r){"use strict";var i,n,s,o,a=[].splice;n=r(0),o=function(t){var e,r,i;for(i={},Reflect.setPrototypeOf(i,null),e=0,r=t.length;e<r;e++)i[t[e]]=!0;return i},s=function(t,e,r){return e?new i(t,function(){var i,s,o;switch(this._filters=t._filters.concat(),e&&e.constructor){case Object:for(i in s=[],e)o=e[i],s.push(r(this,i,o,n.property(i)));return s;case Function:case Array:case String:return r(this,null,e,function(t){return t});default:return console.log({req:e})}}):t},t.exports=i=function(){class t{static build({$sort:e,$memory:r}){var i;return i=null,new t({_all_ids:i,_group:null,_filters:[],$sort:e,$partition:["set"]},function(){return this.all=this,this.$memory=r})}constructor(t,e){this._step=0,this._copy(t),e.call(this)}_copy({all:t,_all_ids:e,_group:r,_filters:i,$sort:n,$partition:s,$page_by:o}){this.all=t,this._all_ids=e,this._group=r,this._filters=i,this.$sort=n,this.$partition=s,this.$page_by=o}in(t){return s(this,t,function(t,e,r,i){var n,s,a;switch(n=function(e){return t._filters.push(e)},null!=(s=null!=r?r.constructor:void 0)?s:r){case Array:return a=o(r),n(function(t){var e,r,n,s;for(e=0,n=(s=i(t)).length;e<n;e++)if(r=s[e],a[r])return!0;return!1});case RegExp:return n(function(t){var e,n,s,o;for(e=0,n=(s=i(t)).length;e<n;e++)if(o=s[e],r.test(o))return!0;return!1});case null:case 0:case"":case Boolean:case String:case Number:return n(function(t){var e;return-1<(null!=(e=i(t))?e.indexOf(r):void 0)});default:throw console.log({target:e,req:[r,null!=r?r.constructor:void 0]}),Error("unimplemented")}})}partition(...e){return new t(this,function(){return this.$partition=e})}where(t){return s(this,t,function(t,e,r,i){var n,s,a;switch(n=function(e){return t._filters.push(e)},null!=(s=null!=r?r.constructor:void 0)?s:r){case Function:return n(r);case Array:return"_id"===e?t._all_ids=r:(a=o(r),n(function(t){return a[i(t)]}));case RegExp:return n(function(t){return r.test(i(t))});case null:case 0:case"":case Boolean:case String:case Number:return"_id"===e?t._all_ids=[r]:n(function(t){return r===i(t)});default:throw console.log({target:e,req:[r,null!=r?r.constructor:void 0]}),Error("unimplemented")}})}search(t){var e,r,i;return t&&(r=function(){var r,i,n,s;for(s=[],r=0,i=(n=t.split(/\s+/)).length;r<i;r++)(e=(e=n[r]).replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")).length&&s.push(`(${e})`);return s}()).length?(i=new RegExp(r.join("|"),"ig"),this.where(function(t){var e;return!(e=t.q.search_words)||i.test(e)})):this}shuffle(){return this.sort(Math.random)}order(...e){var r,i,s;return s=e,[...e]=s,[r]=a.call(e,-1),e.length||e.push("list"),i=["_reduce",...e].join("."),n.isEqual(r,this.$sort[i])?this:new t(this,function(){return this.$sort=n.cloneDeep(this.$sort),this.$sort[i]=r})}sort(...t){return this.order({sort:t})}page(e){return new t(this,function(){return this.$page_by=e})}form(...t){var e,r,i;return(i=this.find(...t))?(r=null!=(e=this.all.$memory[i.id]).form?e.form:e.form={},Reflect.setPrototypeOf(r,i),r):i}find(...t){var e,r,i,n;for(e=0,i=t.length;e<i;e++)if(r=t[e],n=this.hash[r])return n;return null}finds(t){var e,r,i,n,s;for(s=[],e=0,i=t.length;e<i;e++)r=t[e],(n=this.hash[r])&&s.push(n);return s}pluck(){return this.list.pluck(...arguments)}}return Object.defineProperties(t.prototype,{reduce:{get:function(){return this.all._finder.calculate(this,this.all.$memory),this._reduce}},list:{get:function(){return this.reduce.list}},hash:{get:function(){return this.reduce.hash}},memory:{get:function(){return this.all.$memory}},ids:{get:function(){return Object.keys(this.hash)}}}),t}.call(void 0)},function(t,e,r){"use strict";t.exports=class{static bless(t,e,r){return r.bless(t.item),t.meta=e}constructor(t,e){this.meta=t,this.item=e,this.$group=[]}toJSON(t){return{item:this.item,$group:this.$group}}}},function(t,e,r){"use strict";t.exports={Query:r(2),Set:r(7),Map:r(8),List:r(9),Model:r(10),Finder:r(11)}},function(t,e,r){"use strict";var i;t.exports=i=r(1),i.Rule=r(6),i.Base=r(4)},function(t,e,r){"use strict";var i,n,s,o,a,u,l,h,c,f=[].indexOf;h=r(0),o=r(1),({Finder:i,Query:u,Model:a,List:n,Set:l,Map:s}=r(4)),c=function(t){var e,r,i;return t=h.snakeCase(t).replace(/s$/,""),(r=o.Name[t])?r:(e=`${t}s`,o.Name[e]=o.Name[t]=i=o.PureObject(),i.base=t,i.list=e,i.id=`${t}_id`,i.ids=`${t}_ids`,i.deploys=[],i.depends=[],i)},t.exports=class{constructor(t,e){this.$name=c(t),this.state=o.State.base(this.$name.list),this.model=a,this.list=n,this.set=l,this.map=s,this.all=u.build(this.state),this.all.$sort["_reduce.list"]={},this.all._cache={},this.all._finder=new i(this.$name,this.state),this.depend_on(this.$name.list),this.map_property={},({base:t}=this.$name),this.model_property={id:{enumerable:!0,get:function(){return this._id}},[this.$name.id]:{enumerable:!0,get:function(){return this._id}}},this.form_property={changes:{enumerable:!0,value:function(t){return h.isEqual(this[t],this.find[t])?null:this.$model[t]}},isChanged:{enumerable:!0,get:function(){var t,e,r,i;for(t=0,i=(r=Object.keys(this)).length;t<i;t++)if(e=r[t],!h.isEqual(this[e],this.$model[e]))return!0;return!1}}},this.list_property={first:{enumerable:!1,get:function(){return this[0]}},head:{enumerable:!1,get:function(){return this[0]}},tail:{enumerable:!1,get:function(){return this[this.length-1]}},last:{enumerable:!1,get:function(){return this[this.length-1]}},uniq:{enumerable:!1,get:function(){return this.constructor.bless(h.uniq(this))}},pluck:{enumerable:!1,value:function(...t){return e=function(){switch(t.length){case 0:return function(){return null};case 1:return h.property(t[0]);default:return function(e){return h.at(e,...t)}}}(),this.constructor.bless(this.map(e))}}},this.set_property={},e&&this.schema(e)}schema(t){return t.call(this),this.model===a&&(this.model=class extends this.model{}),Object.assign(this.model_property,this.model.prototype),Object.defineProperties(this.model.prototype,this.model_property),this.list===n&&(this.list=class extends this.list{}),Object.assign(this.list_property,this.list.prototype),Object.defineProperties(this.list.prototype,this.list_property),this.set===l&&(this.set=class extends this.set{}),Object.assign(this.set_property,this.set.prototype),Object.defineProperties(this.set.prototype,this.set_property),this.map===s&&(this.map=class extends this.map{}),Object.assign(this.map_property,this.map.prototype),Object.defineProperties(this.map.prototype,this.map_property),this.model.$name=this.list.$name=this.set.$name=this.map.$name=this.$name,this.all._finder.deploy(this),o.Set[this.$name.base]=new this.set(this),o.Query[this.$name.list]=this.all,o.Finder[this.$name.list]=this.all._finder,this}key_by(t){var e;return e=function(){switch(null!=t?t.constructor:void 0){case void 0:return function(){return this._id};case Function:return t;case String:case Array:return h.property(t);default:throw Error(`unimplemented ${t}`)}}(),this.model_property.id={enumerable:!0,get:e}}deploy(t){return this.$name.deploys.push(t)}depend_on(t){return o.Name[t].depends.push(t)}scope(t){var e,r,i,n;for(e in i=[],r=t(this.all))n=r[e],i.push(this.use_cache(e,n));return i}property(t,e){return Object.assign(this[`${t}_property`],e)}default_scope(t){return this.all._copy(t(this.all)),o.State.base(this.$name.list).$sort=this.all.$sort}shuffle(){return this.default_scope(function(t){return t.shuffle()})}sort(...t){return this.default_scope(function(e){return e.sort(...t)})}order(...t){return this.default_scope(function(e){return e.order(...t)})}relation_to_one(t,e,r,i){return this.model_property[t]={enumerable:!0,get:function(){var t;return t=h.get(this,r),o.Query[e].find(t,i)}}}relation_to_many(t,e,r,i,n){var s;return s=this.all,this.use_cache(t,function(t){return o.Query[e][i]({[`${n}`]:t})}),this.model_property[t]={enumerable:!0,get:function(){return s[t](this[r])}}}relation_tree(t,e){var r;return r=this.all,this.use_cache(t,function(i,n){var s;return n?(s=r.where({[`${e}`]:i}),r[t](s.ids,n-1)):r.where({id:i})}),this.model_property[t]={enumerable:!0,value:function(e){return r[t]([this.id],e)}}}relation_graph(t,e){var r;return r=this.all,this.use_cache(t,function(i,n){var s,o,a,u,l,c,f,p,d;if(p=r.where({id:i}),n){for(a=[],o=0,c=(d=p.pluck(e)).length;o<c;o++)if(null!=(s=d[o]))for(u=0,f=s.length;u<f;u++)null!=(l=s[u])&&a.push(l);return r[t](h.uniq(a),n-1)}return p}),this.model_property[t]={enumerable:!0,value:function(e){return r[t]([this.id],e)}}}use_cache(t,e){switch(null!=e?e.constructor:void 0){case Function:return this.all[t]=(...r)=>{var i,n;return null!=(i=this.all._cache)[n=`${t}:${JSON.stringify(r)}`]?i[n]:i[n]=e(...r)};default:return this.all[t]=e}}path(...t){var e,r,i,n,s;for(r=0,n=t.length;r<n;r++)i=t[r],this.belongs_to(i);return this.deploy(function(){var e,r,n,s,o;for(o=this.id.split("-"),this.idx=o[t.length],s=[],e=r=0,n=t.length;r<n;e=++r)i=t[e],s.push(this[`${i}_id`]=o.slice(0,+e+1||9e9).join("-"));return s}),({all:e}=this),s=t.slice(-1)[0]+"_id",this.model_property.siblings={get:function(){var t;return(t={})[s]=this[s],e.where(t)}}}belongs_to(t,e={}){var r,i,n,s;return n=c(t),({key:r=n.id,target:s=n.list,miss:i}=e),this.relation_to_one(n.base,s,r,i)}habtm(t,e={}){var r,i,n;return i=c(t),e.reverse?(({key:r=this.$name.ids,target:n=t}=e),this.relation_to_many(i.list,n,"id","in",r)):(({key:r=i.ids,target:n=i.list}=e),this.relation_to_many(i.list,n,r,"where","id"))}has_many(t,e={}){var r,i,n;return i=c(t),({key:r=this.$name.id,target:n=i.list}=e),this.relation_to_many(i.list,n,"id","where",r)}tree(t={}){var e;return e=this.$name.id,this.relation_tree("nodes",e),this.belongs_to(this.$name.base,t),Object.defineProperties(this.all,{leaf:{get:function(){var t;return t=h.uniq(this.pluck(e)),this.where(function(e){var r;return r=e.id,f.call(t,r)<0})}}})}graph(t={}){var e,r,i;if(({directed:r,cost:e}=t),i=this.$name.ids,this.relation_to_many(this.$name.list,this.$name.list,i,"where","id"),this.relation_graph("path",i),!r)return!0}}},function(t,e,r){"use strict";var i,n,s,o,a,u;r(0),({State:n,Set:i}=r(1)),r(2),o=function(t){return function(e,r){var i,s,o;return o=n.meta(),i=n.base(this.$name.list),s=n.journal(this.$name.list),this.all._finder[t](o,i,s,this.all,e,r)}},u=function(t,e){var r,i,s;if(s=n.meta(),r=n.base(this.$name.list),i=n.journal(this.$name.list),null!=e)return this.all._finder.update(s,r,i,this.all,t,e)},a=function(t){return function(e,r){if(null!=e)return t.call(this,[e],r)}},s=function(){return this.all._finder.clear_cach()},t.exports=i=function(){class t{constructor({all:t,model:e,$name:r}){this.all=t,this.model=e,this.$name=r}find(...t){var e,r,i,s,o,a;for(o=n.meta(),i=n.journal(this.$name.list),e=0,s=t.length;e<s;e++)if(r=t[e],a=this.all.$memory[r])return a.meta=o,i.$memory[r]=a,this.all._finder.clear_cache(),a.item;return null}}return t.prototype.set=o("reset"),t.prototype.reset=o("reset"),t.prototype.merge=o("merge"),t.prototype.add=a(o("merge")),t.prototype.append=a(o("merge")),t.prototype.reject=o("remove"),t.prototype.del=a(o("remove")),t.prototype.remove=a(o("remove")),t.prototype.updates=u,t.prototype.update=a(u),t.prototype.clear_cache=s,t.prototype.refresh=s,t.prototype.rehash=s,t}.call(void 0)},function(t,e,r){"use strict";var i,n,s,o,a,u=[].splice;a=r(0),({State:o,Query:s}=r(1)),n=r(3),i=function(t,e){return Object.defineProperties(t,{_diff:{enumerable:!1,writable:!0,value:null},diff:{enumerable:!1,get:function(){var t,r,n,s,o;return this._diff?this._diff:(this._diff=function(){var i,u,l,h,c;for(c=[],n=i=0,h=this.length-2;0<=h?i<=h:i>=h;n=0<=h?++i:--i){for(t=this[n],r=this[n+1],o={},u=0,l=e.length;u<l;u++)s=e[u],a.set(o,s,a.get(r,s)-a.get(t,s));c.push(o)}return c}.call(this),i(this._diff,e))}}}),t},t.exports=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),t}static $deploy(t,e,r,i,s,o){var a;return a=new n(i,o),this.$deploy_reduce(t,o,e,s,a),this.$deploy_sort(t,o,r,s),a}static $deploy_reduce(t,e,r,i,n){var s,o,a;if(s=o=function(t,r){var i;return t.length?r:(s=function(t,e){return e},i={set:e.id,list:!0},Object.assign(i,r))},a=(t=>(...e)=>{var n,o,a,l,h,c;return c=e,[...e]=c,[o]=u.call(e,-1),o=s(e,o),h=["_reduce",...e].join("."),t.push([h,o]),a=null!=r[h]?r[h]:r[h]={},l=null!=(n=i.$format)[h]?n[h]:n[h]={},this.init(a,o),this.init(l,o)})(n.$group),t.map_partition(e,a),t.map_reduce(e,a),s===o)return a({})}static $deploy_sort(t,e,r,i){var n;return n=function(...t){var e,n,s;return s=t,[...t]=s,[e]=u.call(t,-1),n=["_reduce",...t].join("."),r[n]=e,i.$sort[n]=e},t.order(e,n)}static init(t,e){if(e.id&&(t.id=e.id),e.list&&(t.list=[]),e.count&&(t.count=0),e.all&&(t.all=0),e.set)return t.hash={}}static reduce(t,e,r,i,n){if(i)return n.count&&(i.count+=n.count),n.all&&(i.all+=n.all),n.pow&&(i.pow*=n.pow),n.list&&i.list.push(r),n.set&&(i.hash[n.set]=r),n.max&&(n.max<=i.max||(i.max_is=r,i.max=n.max)),!n.min||i.min<=n.min?void 0:(i.min_is=r,i.min=n.min);console.error("not found $format",e,n,t,r)}static finish(t,e,r,i){if(r)return r.hash&&(r.set=Object.keys(r.hash)),r.count&&null!=r.pow&&(r.avg=Math.pow(r.all,1/r.count)),r.count&&null!=r.all&&(r.avg=r.all*(1/r.count)),null!=r.min&&null!=r.max&&(r.range=r.max-r.min,r.all)?r.density=r.all/r.range:void 0;console.error("not found $format",e,t,i)}static order(t,e,r,i,n){var o,u,l,h,c,f,p,d,m,y,_,g,$,v,b,j,O,w,x;if(b=r,i.belongs_to)if(b instanceof Array)for(d=0,_=b.length;d<_;d++)x=b[d],Reflect.setPrototypeOf(x,s[i.belongs_to].find(x.id));else for(c in b)x=b[c],Reflect.setPrototypeOf(x,s[i.belongs_to].find(c));else if(b.constructor===Object)for(c in b)(x=b[c]).id=c;if(i.sort&&(b=a.orderBy(b,...i.sort)),(w=i.quantile)&&(O=(b.length-1)/w,l=function(){for(var t=[],e=0;0<=w?e<=w:e>=w;0<=w?e++:e--)t.push(e);return t}.apply(this).map(t=>b[Math.floor(t*O)]),b.quantile=l),i.pluck&&(b=function(){var t,e,r;for(r=[],t=0,e=b.length;t<e;t++)j=b[t],(x=a.get(j,i.pluck))&&r.push(x);return r}()),y=i.index){for(o in b){j=b[o],h=(p="number"==typeof a.get(j,y))?[]:{};break}for(o in b)j=b[o],h[f=a.get(j,y)]||(h[f]=u=new n(t)),u.push(j);if(i.mode){if($=null,v=[],p)for(f=m=0,g=h.length;m<g;f=++m)(u=h[f])&&v.length<u.length&&($=f,v=u);else for(f in h)(u=h[f])&&v.length<u.length&&($=f,v=u);v.is_mode=$}b=h}return b}static dash(t,e,r,n,s){var o,a;if(r instanceof Array)return a=r,(o=n.diff)&&(a=i(a,o)),a}static post_proc(t,e,r,i,n){var s,o,a,u,l,h,c,f,p,d,m,y,_;if(p=r,i.cover){for(_=[],o=[],l=0,c=(y=i.cover).length;l<c;l++)r[a=y[l]]?o.push(a):_.push(a);p.remain=_,p.cover=o}if(i.page&&(m=t.$page_by)){for((p=[]).all=r.length,u=h=0,f=r.length;h<f;u=++h)d=r[u],u%m||p.push(s=new n(t)),s.push(d);p.page_idx=function(t){var e,r,i;for(this,i=e=0,r=this.length;e<r;i=++e)if(this[i].includes(t))return i;return null}}return p}}},function(t,e,r){"use strict";var i;i=r(0),r(1),r(2),t.exports=class extends Array{static bless(t,e){return Reflect.setPrototypeOf(t,this.prototype),t.query=e,t}constructor(t){super(),this.query=t}sort(...t){var e;return e=i.orderBy(this,...t),Reflect.setPrototypeOf(e,Reflect.getPrototypeOf(this)),e}group_by(t){var e,r,n;for(e in r=i.groupBy(this,t))n=r[e],Reflect.setPrototypeOf(n,Reflect.getPrototypeOf(this));return r}page_by(t){var e;return e=0,Object.values(this.group_by(function(r){return Math.floor(e++/t)}))}where(t){return this.query.where(t)}in(t){return this.query.in(t)}}},function(t,e,r){"use strict";var i;i=r(0),t.exports=class{static bless(t){return Reflect.setPrototypeOf(t,this.prototype),t}static $deploy(t,e){var r,n,s;for(this.bless(t),e&&i.merge(t,e),r=0,n=(s=this.$name.deploys).length;r<n;r++)s[r].call(t,this);if(!t.id)throw new Error(`detect bad data: ${JSON.stringify(t)}`)}static update(t,e){}static create(t){}static delete(t){}static map_partition(t,e){}static map_reduce(t,e){}static order(t,e){}}},function(t,e,r){"use strict";var i,n,s,o,a,u,l,h,c,f;u=r(0),({Finder:i,State:a,Query:o,Format:n,PureObject:s,step:c}=r(1)),h=function({list:t},e,r){var i,n,s;switch(null!=e?e.constructor:void 0){case Array:for(i=0,s=e.length;i<s;i++)r((n=e[i]).id||n)}},l=function({list:t},e,r){var i,n,s,o;switch(null!=e?e.constructor:void 0){case Array:for(i=0,o=e.length;i<o;i++)r(s=e[i]);break;case Object:for(n in e)(s=e[n])._id=n,r(s)}},f=function(t,e,r){var i,n;if(!t||!r)return!1;for(i=0,n=r.length;i<n;i++)if(!(0,r[i])(t,e))return!1;return!0},t.exports=i=class{constructor(t,{$format:e}){this.$name=t,this.$format=e,a.notify(this.$name.list)}deploy({set:t,map:e,list:r,model:i}){this.set=t,this.map=e,this.list=r,this.model=i}calculate(t,e){var r,i,n,s,o,l;if(t._step<a.step[this.$name.list]){if(delete t._reduce,t._step=c(),r=u.cloneDeep(this.$format),o={_reduce:{list:[],hash:{}}},t._all_ids)this.reduce(this.map,r,o,t,e,t._all_ids);else if(t===t.all)this.reduce(this.map,r,o,t,e,Object.keys(e));else for(i=0,n=(l=t.$partition).length;i<n;i++)s=l[i],this.reduce(this.map,r,o,t,e,u.get(t.all,`reduce.${s}`));this.finish(this.map,r,o,t)}}reduce(t,e,r,i,n,s){var o,a,u,l,h,c,p,d,m,y;if(s){for(y=[],u=0,c=s.length;u<c;u++)l=s[u],(d=n[l])&&(({meta:p,item:h,$group:o}=d),f(h,p,i._filters)&&y.push(function(){var n,s,u;for(u=[],n=0,s=o.length;n<s;n++)[m,a]=o[n],d=r[m]=e[m],u.push(t.reduce(i,m,h,d,a));return u}()));return y}}finish(t,e,r,i){var n,s,o,a,l,h,c,f,p;for(l in r)a=r[l],t.finish(i,l,a,this.list),u.set(i,l,a);for(l in f=[],h=i.$sort)n=h[l],(o=u.get(i,l))&&(p=t.order(i,l,o,n,this.list),s=t.dash(i,l,p,n,this.list),c=t.post_proc(i,l,s,n,this.list),this.list.bless(c,i),c.from=o,f.push(u.set(i,l,c)));return f}clear_cache(t=!0){var e,r,i,n;if(null!=t)for(e=0,r=(n=this.$name.depends).length;e<r;e++)i=n[e],a.notify(i)}reset(t,e,r,i,n,o){var a,u,l,h;for(a in r.$memory=s(),e.$memory=i.$memory=u=s(),this.merge(t,e,r,i,n,o),h=e.$memory)l=h[a],null==u[a]&&this.model.delete(l);return this.clear_cache(!0)}merge(t,e,r,i,n,s){var o;return o=!1,l(this.$name,n,n=>{var a,u;return u=e.$memory[n.id],this.model.$deploy(n,s),a=this.map.$deploy(this.model,this.$format,i.$sort,t,r,n),r.$memory[n.id]=a,e.$memory[n.id]=a,null!=u?this.model.update(n,u.item):this.model.create(n),o=!0}),this.clear_cache(o)}remove(t,e,r,i,n){var s;return s=!1,h(this.$name,n,t=>{var i;if(null!=(i=e.$memory[t]))return this.model.delete(i.item),delete r.$memory[t],delete e.$memory[t],s=!0}),this.clear_cache(s)}update(t,e,r,i,n,s){var o,a;return({$memory:o}=i),a=!1,h(this.$name,n,n=>{var o,l;if(l=e.$memory[n])return u.merge(l.item,s),o=this.map.$deploy(this.model,this.$format,i.$sort,t,r,l.item),r.$memory[n]=o,e.$memory[n]=o,this.model.update(l.item,l.item),a=!0}),this.clear_cache(a)}}}])}); | ||
//# sourceMappingURL=index.min.js.map |
@@ -6,3 +6,4 @@ { | ||
"main": "lib/index.min.js", | ||
"version": "0.4.3", | ||
"typings": "lib/typings.d.ts", | ||
"version": "0.4.4", | ||
"preferGlobal": true, | ||
@@ -24,5 +25,5 @@ "repository": "git@github.com:7korobi/memory-orm.git", | ||
"devDependencies": { | ||
"@babel/core": "^7.4.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.4.4", | ||
"@babel/preset-env": "^7.4.5", | ||
"@babel/core": "^7.5.5", | ||
"@babel/plugin-transform-modules-commonjs": "^7.5.0", | ||
"@babel/preset-env": "^7.5.5", | ||
"babel-jest": "^24.8.0", | ||
@@ -36,4 +37,4 @@ "babel-loader": "^8.0.6", | ||
"npm-run-all": "^4.1.5", | ||
"webpack": "^4.33.0", | ||
"webpack-cli": "^3.3.4", | ||
"webpack": "^4.39.1", | ||
"webpack-cli": "^3.3.6", | ||
"webpack-node-externals": "^1.7.2", | ||
@@ -53,4 +54,5 @@ "yaml-jest": "^1.0.5", | ||
"dependencies": { | ||
"lodash": "^4.17.11" | ||
"@types/lodash": "^4.14.136", | ||
"lodash": "^4.17.15" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
17
6.25%83
2.47%106083
-6.33%2
100%+ Added
+ Added
Updated