UNPKG

basb-cli

Version:
2 lines (1 loc) 4.76 kB
import{L as n,M as e,d as t,m as r,bP as a,dG as o,a3 as i,dH as u,N as s,cF as l,J as c,dI as d,b as f,b8 as m,e as v,dJ as p,K as g,dK as h,bA as I}from"./index.js";var y={value:"eq","<":"lt","<=":"lte",">":"gt",">=":"gte","=":"eq","!=":"ne","<>":"ne"},b=function(){function t(t){if(null==(this._condVal=c(t)?new RegExp(t):d(t)?t:null)){var r;r=n("Illegal regexp",t,"in"),e(r)}}return t.prototype.evaluate=function(n){var e=typeof n;return c(e)?this._condVal.test(n):!!f(e)&&this._condVal.test(n+"")},t}(),x=function(){function n(){}return n.prototype.evaluate=function(){return this.value},n}(),V=function(){function n(){}return n.prototype.evaluate=function(){for(var n=this.children,e=0;e<n.length;e++)if(!n[e].evaluate())return!1;return!0},n}(),w=function(){function n(){}return n.prototype.evaluate=function(){for(var n=this.children,e=0;e<n.length;e++)if(n[e].evaluate())return!0;return!1},n}(),G=function(){function n(){}return n.prototype.evaluate=function(){return!this.child.evaluate()},n}(),D=function(){function n(){}return n.prototype.evaluate=function(){for(var n=!!this.valueParser,e=(0,this.getValue)(this.valueGetterParam),t=n?this.valueParser(e):null,r=0;r<this.subCondList.length;r++)if(!this.subCondList[r].evaluate(n?t:e))return!1;return!0},n}();function F(t,r){if(!0===t||!1===t){var s=new x;return s.value=t,s}var l="";return A(t)||(l=n("Illegal config. Expect a plain object but actually",t),e(l)),t.and?P("and",t,r):t.or?P("or",t,r):t.not?function(t,r){var a=t.not,o="";o=n('"not" condition should only be `not: {}`.',"Illegal condition:",t),A(a)||e(o);var i=new G;i.child=F(a,r),i.child||e(o);return i}(t,r):function(t,r){for(var s="",l=r.prepareGetValue(t),c=[],d=a(t),f=t.parser,m=f?o(f):null,v=0;v<d.length;v++){var p=d[v];if("parser"!==p&&!r.valueGetterAttrMap.get(p)){var g=i(y,p)?y[p]:p,h=t[p],I=m?m(h):h,x=u(g,I)||"reg"===g&&new b(I);x||(s=n('Illegal relational operation: "'+p+'" in condition:',t),e(s)),c.push(x)}}c.length||(s=n("Relational condition must have at least one operator.","Illegal condition:",t),e(s));var V=new D;return V.valueGetterParam=l,V.valueParser=m,V.getValue=r.getValue,V.subCondList=c,V}(t,r)}function P(a,o,i){var u,s=o[a];u=n('"and"/"or" condition should only be `'+a+": [...]` and must not be empty array.","Illegal condition:",o),t(s)||e(u),s.length||e(u);var l="and"===a?new V:new w;return l.children=r(s,(function(n){return F(n,i)})),l.children.length||e(u),l}function A(n){return s(n)&&!l(n)}var C=function(){function n(n,e){this._cond=F(n,e)}return n.prototype.evaluate=function(){return this._cond.evaluate()},n}();var E,R={type:"echarts:filter",transform:function(t){for(var r,a,o,u=t.upstream,s=(a=t.config,o={valueGetterAttrMap:m({dimension:!0}),prepareGetValue:function(t){var r="",a=t.dimension;i(t,"dimension")||(r=n('Relation condition must has prop "dimension" specified.',"Illegal condition:",t),e(r));var o=u.getDimensionInfo(a);return o||(r=n("Can not find dimension info via: "+a+".\n","Existing dimensions: ",u.cloneAllDimensionInfo(),".\n","Illegal condition:",t,".\n"),e(r)),{dimIdx:o.index}},getValue:function(n){return u.retrieveValueFromItem(r,n.dimIdx)}},new C(a,o)),l=[],c=0,d=u.count();c<d;c++)r=u.getRawDataItem(c),s.evaluate()&&l.push(r);return{data:l}}};E=["Valid config is like:",'{ dimension: "age", order: "asc" }','or [{ dimension: "age", order: "asc"], { dimension: "date", order: "desc" }]'].join(" ");var _={type:"echarts:sort",transform:function(t){var r=t.upstream,a=t.config,i="",u=I(a);u.length||e(i="Empty `config` in sort transform.");var s=[];v(u,(function(t){var a=t.dimension,u=t.order,l=t.parser,c=t.incomparable;if(null==a&&e(i='Sort transform config must has "dimension" specified.'+E),"asc"!==u&&"desc"!==u&&e(i='Sort transform config must has "order" specified.'+E),c&&"min"!==c&&"max"!==c){e('incomparable must be "min" or "max" rather than "'+c+'".')}if("asc"!==u&&"desc"!==u){e('order must be "asc" or "desc" rather than "'+u+'".')}var d=r.getDimensionInfo(a);d||(i=n("Can not find dimension info via: "+a+".\n","Existing dimensions: ",r.cloneAllDimensionInfo(),".\n","Illegal config:",t,".\n"),e(i));var f=l?o(l):null;l&&!f&&(i=n("Invalid parser name "+l+".\n","Illegal config:",t,".\n"),e(i)),s.push({dimIdx:d.index,parser:f,comparator:new p(u,c)})}));var l=r.sourceFormat;l!==g&&l!==h&&e(i='sourceFormat "'+l+'" is not supported yet');for(var c=[],d=0,f=r.count();d<f;d++)c.push(r.getRawDataItem(d));return c.sort((function(n,e){for(var t=0;t<s.length;t++){var a=s[t],o=r.retrieveValueFromItem(n,a.dimIdx),i=r.retrieveValueFromItem(e,a.dimIdx);a.parser&&(o=a.parser(o),i=a.parser(i));var u=a.comparator.evaluate(o,i);if(0!==u)return u}return 0})),{data:c}}};function L(n){n.registerTransform(R),n.registerTransform(_)}export{L as install};