chain-able
Version:
interfaces that describe their intentions.
3 lines (2 loc) • 28.6 kB
JavaScript
define(function(){"use strict";function t(t){return J(t)&&!L(t)&&!B(t)}function e(t){return U(t)?[]:{}}function n(n,r){return F(r.clone)&&t(n)?i(e(n),n,r):n}function r(e,r,o){for(var u=e.slice(),a=0;a<r.length;a++){var s=r[a];v(u[a])?u[a]=n(s,o):t(s)?u[a]=i(e[a],s,o):~e.indexOf(s)||u.push(n(s,o))}return u}function o(e,r,o){var u={};if(t(e))for(var a=N(e),s=0;s<a.length;s++)u[a[s]]=n(e[a[s]],o);for(var c=N(r),f=0;f<c.length;f++){var l=c[f];u[l]=t(r[l])&&e[l]?i(e[l],r[l],o):n(r[l],o)}return u}function i(t,e,r){if(U(e)){var i=r.arrayMerge;return U(t)?i(t,e,r):n(e,r)}return o(t,e,r)}function u(t){this.value=t}function a(t,e,n){var r=[],o=[],i=!0;return function t(u){function a(){if(J(l.node)){l.keys&&l.node_===l.node||(l.keys=N(l.node)),l.isLeaf=0===l.keys.length;for(var t=0;t<o.length;t++)if(o[t].node_===u){l.circular=o[t];break}}else l.isLeaf=!0,l.keys=null;l.notLeaf=!l.isLeaf,l.notRoot=!l.isRoot}var c={},f=!0,l={node:n?s(u):u,node_:u,path:[].concat(r),parent:o[o.length-1],parents:o,key:r.slice(-1)[0],isRoot:0===r.length,level:r.length,circular:null,update:function(t,e){l.isRoot||(l.parent.node[l.key]=t),l.node=t,e&&(f=!1)},delete:function(t){delete l.parent.node[l.key],t&&(f=!1)},remove:function(t){v(l.parent)||(U(l.parent.node)?l.parent.node.splice(l.key,1):delete l.parent.node[l.key],t&&(f=!1))},keys:null,before:function(t){c.before=t},after:function(t){c.after=t},pre:function(t){c.pre=t},post:function(t){c.post=t},stop:function(){i=!1},block:function(){f=!1}};if(!i)return l;a();var p=e.call(l,l.node);return!v(p)&&l.update&&l.update(p),c.before&&c.before.call(l,l.node),f?(J(l.node)&&!l.circular&&(o.push(l),a(),gt(l.keys,function(e,o){r.push(e),c.pre&&c.pre.call(l,l.node[e],e);var i=t(l.node[e]);n&&yt(l.node,e)&&(l.node[e]=i.node),i.isLast=o===l.keys.length-1,i.isFirst=0===o,c.post&&c.post.call(l,i),r.pop()}),o.pop()),c.after&&c.after.call(l,l.node),l):l}(t).node}function s(t){if(J(t)){var e;return S(t)?e=Q(t.entries()):j(t)&&(e=Z(t)),e=U(t)?[]:B(t)?new Date(t.getTime?t.getTime():t):L(t)?new RegExp(t):pt(t)?{message:t.message}:K(t)?new Boolean(t):ht(t)?new Number(t):k(t)?new String(t):Object.create(vt(t)),gt(N(t),function(n){e[n]=t[n]}),e}return t}function c(t){if(Bt(t))return Lt(t);for(var e=t.split("|"),n=(t.split("&"),0);n<e.length;n++)l(e[n]);return Kt(t,function(t){for(var n=0;n<e.length;n++)if(Lt(e[n])(t))return!0;return!1}),Lt(t)}function f(t){var e=Jt(t),n=Lt(e),r="?"+e,o=e+"[]",i="!"+e,u=Gt(n,Wt),a=Gt(n,Ht(n));return $t(r)&&Kt(r,u),$t(o)&&Kt(o,a),$t(i)&&Kt(i,Vt(n)),Lt(t)}function l(t){return O(t)?(ft&&console.log("functionType",{fullKey:t}),t):k(t)&&Qt(t)?(ft&&console.log("andOrType",{fullKey:t}),c(t)):(ft&&console.log("arithmeticType",{fullKey:t},f(t)),f(t))}function p(t){var e=vt(t);return[].concat(me(t),be(t),N(t),e?p(e):[])}function h(t,e,n){t[It("set-"+e)]=n.set,t[It("get-"+e)]=n.get}function d(t,e,n){if(!v(n))for(var r=0;r<n.length;r++)T(e,n[r],ge(e,t))}function y(t,e){var n=v(e)?nn:e,r=t;r=t&&t instanceof Object?De.compose(A.compose(t)):De;for(var o=0;o<n.length;o++)r=n[o](r)||r||De;return r}var v=function(t){return void 0===t},g=Symbol.iterator,m=Symbol.hasInstance,b=Symbol.toPrimitive,_=function(t,e){return Object.prototype.isPrototypeOf.call(t,e)},w=function(t){return Object.prototype.toString.call(t)},S=function(t){return t instanceof Map||"[object Map]"===w(t)},j=function(t){return t instanceof Set||"[object Set]"===w(t)},O=function(t){return"function"==typeof t},E=function(t){return"string"==typeof t},k=function(t){return E(t)||"[object String]"===w(t)},x=function(t){return!1===t},N=Object.keys,C=Object.assign,T=function(t,e,n){Object.defineProperty(t,e,C({configurable:!0,enumerable:!0},n))},M=function(t){return"parent"===t||"store"===t||"meta"===t||"className"===t},R="production"!==process.env.NODE_ENV,D=function(t,e){return!M(t)&&(S(e)||j(e)||e&&e.store)},I=function(t){if(R&&(!t||!t.prototype))throw console.log({SuperClass:t}),new TypeError("did not have a super class / target base");var e=function(t){function e(e){t.call(this),e&&(this.parent=e),this.className=this.constructor.name}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype[g]=function(){var t=this.values(),e=this.store.size,n=this.entries?this.entries():0,r=0===n?new Array(e):N(n);return{i:0,next:function(){var o=this.i,i=o,u=t[o];return n&&(i=r[o]),v(i)&&v(u)||e<=o?{value:void 0,done:!0}:(this.i++,{value:[i,u],done:!1})}}},e.prototype.end=function(){return this.parent},e.prototype.when=function(t,e,n){return t?O(e)&&(k(t)?this.get(t)&&e(this):e(this)):O(n)&&n(this),this},e.prototype.clear=function(t){var e=this;if(this.store.clear(),x(t))return this;for(var n=N(this),r=0;r<n.length;r++){var o=n[r];D(o,e[o])&&e[o].clear()}return this},e.prototype.delete=function(t){return this.store.delete(t),this},e.prototype.has=function(t){return this.store.has(t)},e.prototype.values=function(){var t=[];return this.store.forEach(function(e){return t.push(e)}),t},e.prototype[b]=function(t){return"number"===t&&this.toNumber?this.toNumber():this.toJSON?this.toJSON():this.toString()},e}(t),n=e.prototype;return T(n,"length",{enumerable:!1,get:function(){return this.store.size}}),T(n,m,{enumerable:!1,value:function(t){return t&&(_(n,t)||t.store)}}),e},V=I(function(){});V.compose=I;var A=V,G=function(t){return"object"==typeof t},P=function(t){return null===t},z=function(t){return v(t)||P(t)},J=function(t){return!z(t)&&G(t)},U=Array.isArray,F=function(t){return!0===t},L=function(t){return t instanceof RegExp||"[object RegExp]"===w(t)},B=function(t){return t instanceof Date||"[object Date]"===w(t)},K=function(t){return F(t)||x(t)||"[object Boolean]"===w(t)},$=function(t){return U(t)?"array":P(t)?"null":typeof t},q=function(t,e){return t.includes(e)},W=function(t,e,n){if(t===e)return t;var o=C({arrayMerge:r,stringToArray:!0,boolToArray:!1,ignoreTypes:["null","undefined"]},n||{}),u=o.ignoreTypes,a=o.stringToArray,s=o.boolToArray,c=o.clone;return F(q(u,$(t)))?e:F(q(u,$(e)))?t:K(t)&&K(e)?s?[t,e]:e:k(t)&&k(e)?a?[t,e]:t+e:U(t)&&k(e)?(c?t.slice(0):t).concat([e]):k(t)&&U(e)?(c?e.slice(0):e).concat([t]):i(t,e,o)},H=Array.from,Q=function(t){var e={};return 0!==t.size&&(e=H(t.entries()).reduce(function(t,e){var n=e[0],r=e[1];return t[n]=r,t},{})),e},X=function(t){return function(e){for(var n=N(e),r=0;r<n.length;r++){var o=n[r];if(!M(o)){var i=e[o];i&&O(i.entries)&&C(t,{[o]:i.entries(!0)||{}})}}return t}},Y=function(t){return~w(t).indexOf("Iterator")},Z=function(t){return E(t)?t.includes(",")?t.split(","):[t]:t?U(t)?t:j(t)||S(t)||t.values?H(t.values(t)):Y(t)?H(t):[t]:[t]},tt=function(t,e){return Z(t||[]).concat(Z(e))},et=(process,"transformers"),nt=(process,"observers"),rt=(process,"shorthands"),ot=(process,"decorated"),it=function(t){return t===nt},ut=function(t){function e(e,o,a){if("DEBUG"===process.env.NODE_ENV&&console.log("USING META",{key:e,prop:o,value:a}),v(a)){if(v(o))return v(n[e])?[]:0===n[e].size?[]:H(n[e].values());if(!it(e))return v(n[e])?[]:Z(i(e,o));r(e),u(e,o)}else r(e),u(e,o,a);return t}if(t.meta)return t.meta;var n={},r=function(t){v(n[t])&&(n[t]=it(t)?new Set:new Map)},o=function(t,e){return v(e)?!!n[t].size:n[t].has(e)},i=function(t,e){return o(t,e)?n[t].get(e):[]},u=function(t,e,r){var o=n[t];if(j(o))o.add(e);else{var i=o.get(e),u=tt(i,r);o.set(e,u)}};return e.store=n,e},at=function(t){return function(t){function e(e){t.call(this,e),this.store=new Map,this.meta=ut(this)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.tap=function(t,e){return this.set(t,e(this.get(t),W))},e.prototype.from=function(t){for(var e=this,n=N(t),r=0;r<n.length;r++){var o=n[r],i=t[o],u=e[o];u&&u.merge?u.merge(i):O(u)?u.call(e,i):e.set(o,i)}return this},e.prototype.extend=function(t){var e=this;return t.forEach(function(t){e.meta(rt,t),e[t]=function(n){return e.set(t,n)}}),this},e.prototype.entries=function(t){void 0===t&&(t=!1);var e=Q(this.store);if(!1===t)return e;var n=X(e);return n(this),n(e),e},e.prototype.get=function(t){return"debug"===t?this.meta.debug:this.store.get(t)},e.prototype.set=function(t,e){return this.store.set(t,e),this},e}(t)},st=at(A);st.compose=at;var ct=st,ft="debug"===process.env.NODE_ENV,lt=function(t){return J(t)||O(t)},pt=function(t){return t instanceof Error||"[object Error]"===w(t)},ht=function(t){return"number"==typeof t||"[object Number]"===w(t)},dt=function(){for(var t=arguments,e=arguments.length,n=new Array(e),r=0;r<e;++r)n[r]=t[r];return n},yt=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},vt=Object.getPrototypeOf,gt=function(t,e){if(t.forEach)t.forEach(e);else for(var n=0;n<t.length;n++)e(t[n],n,t)},mt=function(t){return new u(t)},bt=mt;u.prototype.get=function(t){for(var e=this.value,n=0;n<t.length;n++){var r=t[n];if(!e||!yt(e,r)){e=void 0;break}e=e[r]}return e},u.prototype.has=function(t){for(var e=this.value,n=0;n<t.length;n++){var r=t[n];if(!e||!yt(e,r))return!1;e=e[r]}return!0},u.prototype.set=function(t,e){for(var n=this.value,r=0;r<t.length-1;r++){var o=t[r];yt(n,o)||(n[o]={}),n=n[o]}return n[t[r]]=e,e},u.prototype.map=function(t){return a(this.value,t,!0)},u.prototype.forEach=function(t){return this.value=a(this.value,t,!1)},u.prototype.reduce=function(t,e){var n=1===arguments.length,r=n?this.value:e;return this.forEach(function(e){this.isRoot&&n||(r=t.call(this,r,e))}),r},u.prototype.paths=function(){var t=[];return this.forEach(function(){t.push(this.path)}),t},u.prototype.nodes=function(){var t=[];return this.forEach(function(){t.push(this.node)}),t},u.prototype.clone=function(){var t=[],e=[];return function n(r){for(var o=0;o<t.length;o++)if(t[o]===r)return e[o];if(J(r)){var i=s(r);return t.push(r),e.push(i),gt(N(r),function(t){i[t]=n(r[t])}),t.pop(),e.pop(),i}return r}(this.value)},gt(N(u.prototype),function(t){mt[t]=function(e){var n=new u(e);return n[t].apply(n,dt.apply(null,arguments).slice(1))}});var _t,wt=new Map,St=function(t,e,n){if(wt.has(e))return wt.get(e);var r=[];return bt(e).forEach(function(){var e=this.path;e&&e.length&&r.push((t?t+".":"")+(e.join?e.join("."):e))}),F(n)&&(r=r.filter(function(t){return!r.some(function(e){return e!==t&&q(e,t)})})),wt.set(e,r),r},jt=function(t,e){return Object.prototype.propertyIsEnumerable.call(t,e)},Ot=function(t){return t.length},Et=function(t){return Ot(t)-1},kt=function(t){if(_t||(_t=new Map),_t.has(t))return _t.get(t);if(U(t))return t;for(var e=t.split("."),n=[],r=0;r<e.length;r++){for(var o=e[r];"\\"===o[Et(o)]&&!v(e[r+1]);)o=o.slice(0,-1)+"."+e[++r];n.push(o)}return _t.set(t,n),n},xt=function(t,e){return lt(t)&&k(e)||U(e)},Nt=function(t,e,n){if(!xt(t,e))return v(n)?t:n;for(var r=kt(e),o=0;o<r.length;o++){if(!jt(t,r[o]))return n;if(t=t[r[o]],z(t)){if(o!==Et(r))return n;break}}return t},Ct=function(t){return k(t)||ht(t)},Tt=function(t){return!z(t)&&!Number.isNaN(t)},Mt=function(t){return lt(t)&&0!==N(t).length},Rt=function(t){return O(t)||t instanceof RegExp},Dt={isObjWithKeys:Mt,isObj:lt,isObject:lt,isObjStrict:J,isFunction:O,isReal:Tt,toS:w,isDate:B,isRegExp:L,isError:pt,isBoolean:K,isNumber:ht,isString:k,isMap:S,isSet:j,isSymbol:function(t){return"[object Symbol]"===w(t)},isPrototypeOf:_,isArray:U,isIterator:Y,isUndefined:v,isNull:P,isMatcher:Rt},It=function(t){return t.replace(/\s+/g,"_").replace(/[_.-](\w|$)/g,function(t,e){return e.toUpperCase()})},Vt=function(t){return function(e){return!t(e)}},At=function(t,e){return function(n){return t(n)&&e(n)}},Gt=function(t,e){return function(n){return t(n)||e(n)}},Pt=function(t){return function(e){for(var n in e)if(!t(e[n]))return!1;return!0}},zt=new ct,Jt=function(t){return t.replace(/[?\[\]!\|]/g,"")},Ut=function(t){return It("is-"+t)},Ft=function(t){return function(e){return t===e||t.includes(e)}},Lt=function(t){return zt.get(t)||zt.get(Ut(t))||Ft(t)},Bt=function(t){return zt.has(t)||zt.get(Ut(t))},Kt=function(t,e){return zt.set(t,e)},$t=Vt(Bt),qt=function(t){return zt.from(W(zt.entries(),t))};qt(Dt);var Wt=At(Vt(Tt),function(t){return""===t}),Ht=function(t){return At(U,Pt(t))},Qt=function(t){return t.includes("|")||t.includes("&")};l.has=Bt,l.get=Lt,l.set=Kt,l.addTypes=qt,l.map=zt;var Xt,Yt=l,Zt=function(t){return Ct(t)||K(t)||!Tt(t)||pt(t)||L(t)},te=function(t,e,n){return(n||Yt(t))(e)},ee=function(t,e){function n(n){if(Zt(n))return te(t,n,e);for(var r=St(!1,n,!0),o=0;o<r.length;o++){var i=r[o]||t,u=Nt(e,i),a=Nt(n,i.split("."));if(!te(u,a))return!1}return!0}return R&&(n.inspect=function(){return{property:t,nestedSchema:e}},n.toString=function(){return JSON.stringify(n.inspect(),null,2)}),n},ne=v,re=function(t){return lt(t)&&!ne(t)||U(t)},oe=function(t){for(var e=this,n=this.parent,r=this.entries(),o=r.onValid,i=r.onInvalid,u=r.define,a=r.getSet,s=N(t),c=0;c<s.length;c++){var f=s[c],l=t[f],p=e.newThis().name(f);i&&p.onInvalid(i),o&&p.onValid(o),u&&p.define(),a&&p.getSet();var h=l;if(re(l)){var d=ee(f,l);R&&(d.schema=l),h=d}n.meta&&n.meta("schema",f,l),p.type(h).build()}return n},ie=function(t){return function(){throw R&&console.log(t),t}},ue=function(t,e){return function(n,r,o){var i=w(n),u={[t]:{type:e,arg:{val:n,str:i,json:JSON.stringify(n)}}},a=C(new TypeError(i+" != "+e),u,o);return r&&r.message&&(a.message+=r.message),r&&r.stack&&(a.stack=r.stack),R&&(a.inspect=function(){var t="thrown: "+r,i="compare: "+a.message,u="name: "+a.name,s="arg: "+n+";\nstr: "+w(n)+" "+typeof n+";\njson: "+JSON.stringify(n),c="type: "+e,f="stack: "+a.stack,l="\n----- inspecting on development -----\n";return o&&(l+="meta: "+JSON.stringify(o)+"\n"),l+=t+"\n"+i+"\n"+u+"\n\n",l+=c+"\n"+s,l+="\n\n"+f+"\n-----\n"}),a.reThrow=ie(a),a}},ae=function(t){return function(e,n){return function(r,o,i){var u;try{return u=t(r,o,i),e?e(u):u}catch(t){return n?n(t):t}}}},se=function(t,e){var n,r,o=e?e(t):ae(t),i=function(t,e,i){return o(r,n)(t,e,i)};return i.then=i.onInvalid=function(t){return n=t,i},i.catch=i.onValid=function(t){return r=t,i},i},ce={m:1},fe=function(t,e,n){return function(e,r,o){var i=ue(t,r),u=se(e,o),a=n.onCall||n.onSet,s=n.onValid||a,c=n.onInvalid||function(t,e){return i(t,e,ce).reThrow()};return function(e){var n=this;return u.onInvalid(function(r){c.call(n,i(e,r),e,t,n)}).onValid(function(){s.call(n,e,t,n)}).call(this,e),this}}},le=function(t){return function(e){return function(n,r){return function(o,i,u){var a=e(o,i,u);return t(a)?n(a):r(a)}}}}(Vt(x)),pe=function(t,e,n){var r=n.type;if(r){var o=Yt(r),i=fe(t,0,n)(o,r,le);R&&(i.type=r),this.onCall(i).onSet(i)}},he=function(t,e){var n=this,r=t[e];return O(r)?function(){n.define(!1),n.onCall(r)}:function(){n.from(r),r.set&&n.onSet(r.set),r.get&&n.onGet(r.get),r.call&&n.onCall(r.call),r.set&&r.get&&n.define().getSet()}},de=function(t){return this.target(t),t.meta=ut(t),this.plugin(function(e){return t.meta(ot,e),this.returns(function(e){return e||t}).callReturns(!0)})},ye=function(t,e){return this.initial(0).onCall(function(){return e.tap(t,function(t){return t+1})})},ve=function(t,e){var n=function(n){return v(n)?e.get(t):e.set(t,n)};return n.autoGetSet=!0,this.onSet(n).onGet(n).onCall(n)},ge=Object.getOwnPropertyDescriptor,me=Object.getOwnPropertyNames,be=Object.getOwnPropertySymbols,_e=p,we=function(t){var e=_e(t);bt(t).forEach(function(){var t=this.value;U(t)||lt(t)||this.remove()});for(var n=0;n<e.length;n++)delete t[n];e=void 0,t=void 0},Se=["onInvalid","onValid","initial","default","type","callReturns","target","onSet","onCall","onGet"],je=function(t){function e(n){var r=this;t.call(this,n);var o=this.set.bind(this);this.newThis=function(){return new e(n)},this.toNumber=function(){return r.build(0)},this.extend(Se),this.method=this.methods=function(t){return r.length?r.build().methods(t):r.name(t)},this.encase=function(t){return o("encase",n[t]||t||!0)},this.then=this.onValid.bind(this),this.catch=this.onInvalid.bind(this),this.returns=function(t,e){return o("returns",t||n).callReturns(e)},this.chainable=this.returns,this.alias=function(t){return r.tap("alias",function(e,n){return n(e,Z(t))})},this.plugin=function(t){return r.tap("plugins",function(e,n){return n(e,Z(t))})},this.camelCase=function(){return o("camel",!0)};var i=function(t){return!!v(t)||t};this.define=function(t){return o("define",i(t))},this.getSet=function(t){return o("getSet",i(t))},this.bind=function(t){return o("bind",v(t)?n:t)},this.autoGetSet=function(){return r.plugin(ve)},this.plugin(pe),Mt(Xt)&&N(Xt).forEach(function(t){r[t]=function(e){return Xt[t].call(r,e)},R&&(r[t].methodFactory=!0)})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.name=function(t){var e=this,n=t;if(!U(t)&<(t)){n=N(t);for(var r=0;r<n.length;r++)e.plugin(he.call(e,t,n[r]))}return this.set("names",n)},e.prototype.schema=function(t){return oe.call(this,t)},e.prototype.build=function(t){for(var e=this,n=this.parent,r=Z(this.get("names")),o=this.get("camel"),i=0;i<r.length;i++)e._build(o?It(r[i]):r[i],n);return this.clear(),delete this.parent,we(this),v(t)?n:t},e.prototype._defaults=function(t,e,n){var r=function(n){return e.set(t,n)},o=function(){return e.get(t)};r.defaulted=!0,o.defaulted=!0;var i=n.onCall,u=n.onSet,a=n.onGet;a&&!a.defaulted||this.onGet(o),i&&!i.defaulted||this.onCall(r),u&&!u.defaulted||this.onSet(r)},e.prototype._build=function(t,e){var n,r,o=this,i=function(){return o.entries()};if(yt(e,t)){if(r=ge(e,t),x(r.configurable))return;n=r.value,R&&(n.decorated=!0),this.onCall(n).onSet(n)}else e[t]&&(n=e[t],R&&(n.decorated=!0),this.onCall(n).onSet(n));var u=i();this._defaults(t,e,u);var a=u.plugins;if(a)for(var s=0;s<a.length;s++)u=i(),a[s].call(o,t,e,u);if((u=i()).encase){var c=fe.call(this,t,e,u)(n);R&&(c.encased=n),this.onCall(c).onSet(c),n=c,u=i()}var f=u.getSet,l=u.define,p=u.default,y=u.onGet,g=u.onSet,m=u.onCall,b=u.initial,_=u.bind,w=u.returns,S=u.callReturns,j=u.alias;if(n||(n=function(t){return void 0===t&&(t=p),m.call(e,t)},R&&(n.created=!0)),_&&(n=n.bind(_)),w){var O=n;n=function(){var t=dt.apply(null,arguments),n=O.apply(e,t);return F(S)?w.apply(e,[n].concat(t)):w}}v(b)||e.set(t,b),R&&(T(y,"name",{value:It(y.name+"+get-"+t)}),T(g,"name",{value:It(g.name+"+set-"+t)}),T(m,"name",{value:It(m.name+"+call-"+t)}),T(n,"name",{value:It(""+t)}),u.type&&(n.type=u.type),b&&(n.initial=b),_&&(n.bound=_),w&&(n.returns=w),j&&(n.alias=j),S&&(n.callReturns=S),y&&(n._get=y),g&&(n._set=g),m!=m&&(n._call=m)),ft&&console.log({name:t,defaultValue:p,initial:b,returns:w,onGet:y,onSet:g,method:n.toString()});var E={get:y,set:g},k=l?E:{value:n};r&&(k=C(r,k)),k.value&&k.get&&delete k.value,v(k.writable)||delete k.writable;var N=this.get("target")||e;T(N,t,k),f&&(N.meta&&N.meta(rt,t,g),h(N,t,E)),d(t,N,j)},e.prototype.decorate=function(t){if(R&&!t&&!this.parent.parent)throw new Error("must provide parent argument");return de.call(this,t||this.parent.parent)},e.prototype.autoIncrement=function(){return this.plugin(ye)},e}(ct);je.add=function(t){C(Xt,t)},Xt=je.add;var Oe=je,Ee=function(t){return S(t)||t instanceof A},ke="onExisting",xe="onValue",Ne="merger",Ce="obj",Te=function(t){function e(e){t.call(this,e),this.extend([ke,xe,Ce]).set(xe,function(){return!0}).set(Ne,W)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.init=function(t){return new e(t)},e.prototype.merger=function(t){return O(t)?this.set(Ne,t):this.set("opts",t)},e.prototype.merge=function(t){var e=this,n=this.parent,r=function(t){return e.get(t)},o=r(ke),i=r(xe),u=r("opts"),a=t||r(Ce),s=r(Ne),c=n.meta?n.meta(rt):{},f=N(a);if(R&&!a)throw console.log({onExisting:o,opts:u,obj:a,merger:s,shorthands:c,keys:f,parent:n}),new Error("must provide an object to merge");for(var l=0,p=f.length;l<p;l++){var h=f[l],d=a[h];v(c[h])||c[h]===h||(ft&&console.log("had a shorthand with a diff key than the object (likely @alias)",{shorthandMethod:c[h],key:h,value:d}),h=c[h]);var y=n[h];i(d,h,e)?Ee(y)?(ft&&console.log("has method or shorthand"),n[h].merge(d)):y?(ft&&console.log("has method or shorthand",{method:y,key:h,value:d}),function(t,e){var r=function(e,r){return O(n[t])?n[e](r):n.set(e,r)};if(F(n.has(t))){var i=n.get(t);v(o)?(ft&&console.log("parent has: no onExisting",{existing:i,[t]:e}),r(t,s(i,e,u))):(ft&&console.log("parent has: has onExisting",{existing:i,onExisting:o,[t]:e}),r(t,o(i,e,u)))}else ft&&console.log("parent does not have",{[t]:e}),r(t,e)}(h,d)):(ft&&console.log("went to default",{method:y,key:h,value:d}),n.set(h,d)):ft&&console.log("had onValue, was false, ignored",{onValue:i,key:h,value:d})}return n},e}(ct),Me=function(t){return function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.methods=function(t){return this.method(t)},e.prototype.method=function(t){return new Oe(this).name(t)},e.prototype.merge=function(t,e){var n=Te.init(this);return v(e)?n.merge(t):e(n.obj(t)),this},e}(t===ct?t:ct.compose(t))},Re=Me(ct);Re.compose=Me;var De=Re,Ie=function(t){function e(e){t.call(this,e),this.store=new Set}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.add=function(t){return this.store.add(t),this},e.prototype.prepend=function(e){return this.store=new Set([e].concat(t.prototype.values.call(this))),this},e.prototype.merge=function(t){for(var e=this,n=Z(t),r=0;r<n.length;r++)e.store.add(n[r]);return this},e}(A),Ve="onChainUpDown",Ae="onDone",Ge=function(t){function e(e){t.call(this,e),this.data={},this._calls=new Set,this.factory().extend(["optional","required",Ve,Ae]).set("len",0)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.chainUpDowns=function(t){var e=arguments,n=this;return t.forEach(function(t){n[t]=function(){return n.end(),n.parent[t].apply(n.parent,e)}}),this},e.prototype.props=function(t){var e=this;return t.forEach(function(t){return e.prop(t)}),this},e.prototype.prop=function(t,e){var n=this;return this.tap("len",function(t){return t+1}),!v(this[t])&&F(this.has(Ve))?(this.end(),this.get(Ve)()[t](e)):(this[t]=function(r){return ft&&console.log("called "+t+" with:",r,"calls length is now:",n._calls.size),v(e)?n.data[t]=r:e(r),n._calls.add(t),n._calls.size===n.get("len")?n.end():n},this)},e.prototype.getData=function(t){return v(t)?this.data:this.data[t]},e.prototype.factory=function(t){var e=this;return this.end=function(n){var r;return t&&!v(t.end)?r=t.end:e.has(Ae)&&(r=e.get(Ae)),r&&(r=r.call(e,e.data,e.parent,e,n)),r&&r!==e?r:e.parent},this},e}(De),Pe=function(t,e){return t==e},ze=function(t,e,n){var r=!0,o=e;return bt(t).forEach(function(t){var i=function(){r=!1};if(!this.isRoot){if(!G(o))return i();o=o[this.key]}var u=o;if(this.post(function(){o=u}),ft&&console.log("types: ",{x:w(u),y:w(t)}),this.circular)ft&&console.log("circular",this),bt(e).get(this.circular.path)!==u&&i();else if(z(u)||z(t))u!==t&&i();else if(typeof u!=typeof t)ft&&console.log("diff types",typeof u,typeof t),F(n)&&Pe(u,t)||i();else if(u.__proto__!==t.__proto__)i();else if(u===t);else if(J(u))if(L(u)||L(t))u&&t&&u.toString()===t.toString()||i();else if(B(u)||B(t))B(u)&&B(t)&&u.getTime()===t.getTime()||i();else{var a=N(u),s=N(t).length;if(a.length!==s)return i();for(var c=0;c<a.length;c++)yt(t,a[c])||i()}else w(u)===w(t)&&u!==t?(ft&&console.log("same str types - diff values",{s:w(u),x:u,y:t}),i()):w(u)!==w(t)&&(ft&&console.log("diff str types",{x:w(u),y:w(t)}),i())}),r},Je=function(t){return t.replace(/[|\\{}()[\]^$+*?.]/g,"\\$&")},Ue=function(t){return Je(t).replace(/\\\*/g,".*")},Fe={};Fe.make=function(t,e,n){if(wt.has(t))return wt.get(t);var r=t;if(Rt(r)&&!r.test&&(r.test=r),Rt(r))return r;var o="!"===r[0];return o&&(r=r.slice(1)),r=Ue(r),o&&e&&(r="(?!"+r+")"),n&&(r="^"+r+"$"),r=new RegExp(""+r,"i"),r.negated=o,wt.set(t,r),r},Fe.matcher=function(t,e,n,r){e=Z(e).map(function(t){return Fe.make(t,n,r)}),t=Z(t);for(var o=e[0].negated,i=[],u=0;u<t.length;u++){for(var a=t[u],s=o,c=0;c<e.length;c++)e[c].test(a)&&(s=!e[c].negated);s&&i.push(a)}return i};var Le=C(Fe.matcher,Fe),Be={has:function(t,e){if(!xt(t,e))return!1;for(var n=kt(e),r=0;r<n.length;r++){if(!lt(t))return!1;if(!(n[r]in t))return!1;t=t[n[r]]}return!0},get:Nt,set:function(t,e,n){if(xt(t,e))for(var r=kt(e),o=0;o<r.length;o++){var i=r[o];lt(t[i])||(t[i]={}),o===Et(r)&&(t[i]=n),t=t[i]}},delete:function(t,e){if(xt(t,e))for(var n=kt(e),r=0;r<n.length;r++){var o=n[r];if(r===Et(n))return void delete t[o];if(t=t[o],!lt(t))return}}},Ke=new Map,$e=function(t){return function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.observe=function(t,e){var n=this,r=Z(t),o=r.join("_"),i={};return this.meta(nt,function(t){for(var u=Le(t.key,r),a=0;a<u.length;a++){var s=kt(u[a]);Be.set(i,s,n.get(s))}Ke.has(o)&&ze(Ke.get(o),i)||(Ke.set(o,bt(i).clone()),e.call(n,i,n))})},e}(t)},qe=function(t){return function(t){function e(e){t.call(this,e),e&&e.meta?this.meta.debug=e.meta.debug:this.debug(!1)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.debug=function(t){return this.meta.debug=!!v(t)||t,this},e.prototype.setIfEmpty=function(t,e){return x(this.has(t))?this.set(t,e):this},e.prototype.return=function(t){return t},e.prototype.wrap=function(t){return O(t)&&t.call(this,this),this},e}(t)},We=function(t,e,n){return k(t)?!!new RegExp(Je(t)).test(e):O(t)&&!t.test?!!t(e):!!t.test(e,n)},He=function(t,e){return function(n,r){for(var o=0;o<t.length;o++)if(We(t[o],n,r))return!0;for(var i=0;i<e.length;i++)if(We(e[i],r,n))return!0;return!1}},Qe=["obj","keys","vals","onNonMatch","onMatch","clone"],Xe=function(t){function e(e){t.call(this,e),this.call=this.traverse.bind(this),this.extend(Qe).keys([]).vals([]).onMatch(function(t,e){return e.remove()})}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.traverse=function(t){var e=this.entries(),n=e.obj,r=e.keys,o=e.vals,i=e.onMatch,u=e.onNonMatch,a=e.clone?bt(n).clone():n,s=He(r,o);return bt(n).forEach(function(t){s(this.key,t)?i(t,this):u&&u(t,this)}),this.set(1,a),F(t)?a:this},e.prototype.traversed=function(){return this.get(1)},e}(ct),Ye=function(t){return function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.traverse=function(t){return void 0===t&&(t=!1),new Xe(this).obj(x(t)?this.entries(!0):F(t)?this:t)},e.prototype.transform=function(t,e){return this.meta(et,t,e)},e.prototype.set=function(e,n,r){for(var o=this,i=n,u=this.meta(et,e),a=0;a<u.length;a++)i=u[a].call(o,i,o);t.prototype.set.call(this,e,i);var s={key:r,value:i};v(r)&&(s.key=lt(i)?St(e,i):e);for(var c=this.meta(nt),f=0;f<c.length;f++)c[f](s);return this},e.prototype.remap=function(t,e){var n=this,r=t;return lt(t)||(r={[t]:e}),N(r).forEach(function(t){return n.transform(t,function(e){return n.set(r[t],e),e})}),this},e}(t)},Ze=function(t){return U(t)||k(t)&&t.includes(".")},tn=function(t,e){return!1!==e.meta.dot&&Ze(t)},en=function(t){return function(t){function e(){t.apply(this,arguments)}return t&&(e.__proto__=t),e.prototype=Object.create(t&&t.prototype),e.prototype.constructor=e,e.prototype.dot=function(t){return this.meta.dot=t,this},e.prototype.set=function(e,n){if(tn(e,this)){var r=e.split(".").shift(),o=t.prototype.entries.call(this);return Be.set(o,e,n),t.prototype.set.call(this,r,o[r],e)}return t.prototype.set.call(this,e,n)},e.prototype.get=function(e,n){return tn(e,this)?Be.get(t.prototype.entries.call(this),e,n):t.prototype.get.call(this,e)},e.prototype.has=function(e){return tn(e,this)?Be.has(t.prototype.entries.call(this),e):t.prototype.has.call(this,e)},e.prototype.delete=function(e){return tn(e,this)?Be.delete(t.prototype.entries.call(this),e):t.prototype.delete.call(this,e)},e}(t)},nn=[$e,qe,Ye,en];y.Observe=$e,y.Shorthands=qe,y.Transform=Ye,y.DotProp=en;var rn=y,on=function(t){return U(t)&&0!==t.length},un=function(t){return N(t).reduce(function(e,n){var r=t[n];return Tt(r)&&(on(r)||Mt(r))&&(e[n]=r),e},{})},an=Yt;return function(t){return t&&t.__esModule?t.default:t}(function(t,e){return e={exports:{}},t(e),e.exports}(function(t){var e=rn();e.chainable=function(t){return new e(t)},e.builder=function(t){return new Oe(t)},e.Chain=e,e.compose=rn,e.traverse=bt,e.addMethodFactories=Oe.add,e.toArr=Z,e.camelCase=It,e.dot=Be,e.matcher=Le,e.is=Dt,e.reduce=Q,e.clean=un,e.meta=ut,e.eq=ze,e.types=an,e.addTypes=e.types.addTypes,e.Chainable=A,e.ChainedSet=Ie,e.ChainedMap=De,e.FactoryChain=Ge,e.MethodChain=Oe,e.MergeChain=Te,e.merge=W,t.exports=e}))});
//# sourceMappingURL=index.js.map