@steedos/filters 2.4.0-beta.8 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/steedos-filters.umd.js +6 -4
- package/dist/steedos-filters.umd.min.js +1 -1
- package/lib/filter.js +2 -2
- package/lib/format.js +4 -2
- package/package.json +2 -2
|
@@ -270,7 +270,7 @@
|
|
|
270
270
|
return this.serializeValueV2(value);
|
|
271
271
|
},
|
|
272
272
|
serializeString(value) {
|
|
273
|
-
return "'" + value.replace(/'/g, "''")
|
|
273
|
+
return "'" + value.replace(/'/g, "''") + "'";
|
|
274
274
|
},
|
|
275
275
|
serializeDate(value, serializationFormat) {
|
|
276
276
|
if (!serializationFormat) {
|
|
@@ -366,7 +366,7 @@
|
|
|
366
366
|
return (prop, val)=> {
|
|
367
367
|
var bag = [op, "("];
|
|
368
368
|
|
|
369
|
-
if (this.forceLowerCase) {
|
|
369
|
+
if (val && this.forceLowerCase) {
|
|
370
370
|
// prop = prop.indexOf("tolower(") === -1 ? "tolower(" + prop + ")" : prop;
|
|
371
371
|
// forceLowerCase时不需要在prop外面增加tolower(..),因为odata-v4-mongodb等包不支持
|
|
372
372
|
val = val.toLowerCase();
|
|
@@ -870,12 +870,14 @@
|
|
|
870
870
|
|
|
871
871
|
const _evaluateFormula = evaluateFormula;
|
|
872
872
|
|
|
873
|
-
// 正则包括encodeURIComponent函数编码的
|
|
873
|
+
// 正则包括encodeURIComponent函数编码的12个特殊符号;/?:@&=+$,#%
|
|
874
874
|
// 还包括convertSpecialCharacter函数中转义的特殊符号^$()*+?.\|[]{}
|
|
875
875
|
// 注意encodeURIComponent("\\(")的结果是%5C(,需要特别处理
|
|
876
876
|
// 注意encodeURIComponent("\\.")的结果是%5C.,需要特别处理
|
|
877
877
|
// 注意encodeURIComponent("\\*")的结果是%5C*,因为不需要encodeURIComponent函数编码,所以不用加入REG_FOR_ENCORD变量
|
|
878
|
-
|
|
878
|
+
// %号很特别,\%(?!25)表示包含%且%后续不跟随25,即不匹配%25,其他特殊字符比如?执行encodeURIComponent后也包含%,所以特殊字符都需要处理
|
|
879
|
+
// 因为注意encodeURIComponent("%")结果为%25,它本身也包含了%号,即encodeURIComponent("%25")结果为%2525,所以需要排除%25这种字符串,让它不会再次执行encodeURIComponent
|
|
880
|
+
const REG_FOR_ENCORD = /\;|\/|\?|\:|\@|\&|\=|\+|\$|\,|\#|\%(?!25|3B|3b|2F|2f|3F|3f|3A|3a|40|26|3D|3d|2B|2b|24|2C|2c|23|5C|5c|5E|5e|7C|7c|5B|5b|5D|5d|7B|7b|7D|7d)|\^|(\\\()|(\\\))|(\\\.)|\\|\||\[|\]|\{|\}/;
|
|
879
881
|
|
|
880
882
|
/**
|
|
881
883
|
^$()*+?.\|[]{}等特殊符号需要转义,否则有可能会报错且无法正确识别
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports,require("lodash"),require("moment")):typeof define==="function"&&define.amd?define(["exports","lodash","moment"],factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,factory(global.SteedosFilters={},global._,global.moment))})(this,function(exports,lodash,moment){function _interopDefaultLegacy(e){return e&&typeof e==="object"&&"default"in e?e:{default:e}}var moment__default=_interopDefaultLegacy(moment);function leftPad(text,length){while(text.length<length){text="0"+text}return text}var FORMAT_TYPES={3:"abbreviated",4:"wide",5:"narrow"};var LDML_FORMATTERS={y:function(date,count,useUtc){var year=date[useUtc?"getUTCFullYear":"getFullYear"]();if(count===2){year=year%100}return leftPad(year.toString(),count)},M:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getMonthNames(formatType,"format")[month]}return leftPad((month+1).toString(),Math.min(count,2))},L:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getMonthNames(formatType,"standalone")[month]}return leftPad((month+1).toString(),Math.min(count,2))},Q:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var quarter=Math.floor(month/3);var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getQuarterNames(formatType)[quarter]}return leftPad((quarter+1).toString(),Math.min(count,2))},E:function(date,count,useUtc,dateParts){var day=date[useUtc?"getUTCDay":"getDay"]();var formatType=FORMAT_TYPES[count<3?3:count];return dateParts.getDayNames(formatType)[day]},a:function(date,count,useUtc,dateParts){var hours=date[useUtc?"getUTCHours":"getHours"](),period=hours<12?0:1,formatType=FORMAT_TYPES[count];return dateParts.getPeriodNames(formatType)[period]},d:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCDate":"getDate"]().toString(),Math.min(count,2))},H:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCHours":"getHours"]().toString(),Math.min(count,2))},h:function(date,count,useUtc){var hours=date[useUtc?"getUTCHours":"getHours"]();return leftPad((hours%12||12).toString(),Math.min(count,2))},m:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCMinutes":"getMinutes"]().toString(),Math.min(count,2))},s:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCSeconds":"getSeconds"]().toString(),Math.min(count,2))},S:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCMilliseconds":"getMilliseconds"]().toString(),3).substr(0,count)},x:function(date,count,useUtc){var timezoneOffset=useUtc?0:date.getTimezoneOffset(),signPart=timezoneOffset>0?"-":"+",timezoneOffsetAbs=Math.abs(timezoneOffset),hours=Math.floor(timezoneOffsetAbs/60),minutes=timezoneOffsetAbs%60,hoursPart=leftPad(hours.toString(),2),minutesPart=leftPad(minutes.toString(),2);return signPart+hoursPart+(count>=3?":":"")+(count>1||minutes?minutesPart:"")},X:function(date,count,useUtc){if(useUtc||!date.getTimezoneOffset()){return"Z"}return LDML_FORMATTERS.x(date,count,useUtc)},Z:function(date,count,useUtc){return LDML_FORMATTERS.X(date,count>=5?3:2,useUtc)}};var getFormatter=function(format,dateParts){return function(date){var charIndex,formatter,char,charCount=0,separator="'",isEscaping=false,isCurrentCharEqualsNext,result="";if(!date)return null;if(!format)return date;var useUtc=format[format.length-1]==="Z"||format.slice(-3)==="'Z'";for(charIndex=0;charIndex<format.length;charIndex++){char=format[charIndex];formatter=LDML_FORMATTERS[char];isCurrentCharEqualsNext=char===format[charIndex+1];charCount++;if(!isCurrentCharEqualsNext){if(formatter&&!isEscaping){result+=formatter(date,charCount,useUtc,dateParts)}charCount=0}if(char===separator&&!isCurrentCharEqualsNext){isEscaping=!isEscaping}else if(isEscaping||!formatter){result+=char}if(char===separator&&isCurrentCharEqualsNext){charIndex++}}return result}};const _getFormatter=getFormatter;var MONTHS=["January","February","March","April","May","June","July","August","September","October","November","December"],DAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],PERIODS=["AM","PM"],QUARTERS=["Q1","Q2","Q3","Q4"];var cutCaptions=function(captions,format){var lengthByFormat={abbreviated:3,short:2,narrow:1};return captions.map(function(caption){return caption.substr(0,lengthByFormat[format])})};function getMonthNames(format){return cutCaptions(MONTHS,format)}function getDayNames(format){return cutCaptions(DAYS,format)}function getQuarterNames(format){return QUARTERS}function getPeriodNames(format){return PERIODS}var defaultDateNames={getMonthNames:getMonthNames,getDayNames:getDayNames,getQuarterNames:getQuarterNames,getPeriodNames:getPeriodNames};const DevExpressData={utils:{isConjunctiveOperator:function(condition){return/^(and|&&|&)$/i.test(condition)},normalizeBinaryCriterion:function(crit){return[crit[0],crit.length<3?"=":String(crit[1]).toLowerCase(),crit.length<2?true:crit[crit.length-1]]},isUnaryOperation:function(crit){return crit[0]==="!"&&Array.isArray(crit[1])}}};const DevExpressOData={pad(text,length,right){text=String(text);while(text.length<length){text=right?text+"0":"0"+text}return text},padLeft2(text){return this.pad(text,2)},serializePropName(propName){return propName.replace(/\./g,"/")},serializeValue(value,protocolVersion){if(value===undefined){return null}switch(protocolVersion){case 2:return this.serializeValueV2(value);case 3:return this.serializeValueV2(value);case 4:return this.serializeValueV4(value);default:return this.serializeValueV4(value)}},serializeValueV2(value){if(value instanceof Date){return this.serializeDate(value)}if(typeof value==="string"){return this.serializeString(value)}return String(value)},serializeValueV4(value){if(value instanceof Date){return this.formatISO8601(value,false,false)}if(Array.isArray(value)){return"["+value.map(item=>{return this.serializeValueV4(item)}).join(",")+"]"}return this.serializeValueV2(value)},serializeString(value){return"'"+value.replace(/'/g,"''").replace(/%/g,"%25")+"'"},serializeDate(value,serializationFormat){if(!serializationFormat){return value}if(!(value instanceof Date)){return null}if(serializationFormat==="number"){return value&&value.valueOf?value.valueOf():null}return _getFormatter(serializationFormat,defaultDateNames)(value)},formatISO8601(date,skipZeroTime,skipTimezone){var bag=[];var isZeroTime=function(){return date.getUTCHours()+date.getUTCMinutes()+date.getUTCSeconds()+date.getUTCMilliseconds()<1};bag.push(date.getUTCFullYear());bag.push("-");bag.push(this.padLeft2(date.getUTCMonth()+1));bag.push("-");bag.push(this.padLeft2(date.getUTCDate()));if(!(skipZeroTime&&isZeroTime())){bag.push("T");bag.push(this.padLeft2(date.getUTCHours()));bag.push(":");bag.push(this.padLeft2(date.getUTCMinutes()));bag.push(":");bag.push(this.padLeft2(date.getUTCSeconds()));if(date.getUTCMilliseconds()){bag.push(".");bag.push(this.pad(date.getUTCMilliseconds(),3))}if(!skipTimezone){bag.push("Z")}}return bag.join("")}};class SteedosFilter{constructor(filters,odataProtocolVersion=4,forceLowerCase=true){this.filters=filters||[];this.protocolVersion=odataProtocolVersion;this.forceLowerCase=forceLowerCase;this.formatters={"=":this.createBinaryOperationFormatter("eq"),"<>":this.createBinaryOperationFormatter("ne"),">":this.createBinaryOperationFormatter("gt"),">=":this.createBinaryOperationFormatter("ge"),"<":this.createBinaryOperationFormatter("lt"),"<=":this.createBinaryOperationFormatter("le"),startswith:this.createStringFuncFormatter("startswith"),endswith:this.createStringFuncFormatter("endswith")};this.formattersV2={...this.formatters,...{contains:this.createStringFuncFormatter("substringof",true),notcontains:this.createStringFuncFormatter("not substringof",true)}};this.formattersV4={...this.formatters,...{contains:this.createStringFuncFormatter("contains"),notcontains:this.createStringFuncFormatter("not contains"),notstartswith:this.createStringFuncFormatter("not startswith"),notendswith:this.createStringFuncFormatter("not endswith"),in:this.createBinaryOperationFormatter("in"),notin:this.createBinaryOperationFormatter("notin")}}}createBinaryOperationFormatter(op){return(prop,val)=>{return prop+" "+op+" "+val}}createStringFuncFormatter(op,reverse){return(prop,val)=>{var bag=[op,"("];if(this.forceLowerCase){val=val.toLowerCase()}if(reverse){bag.push(val,",",prop)}else{bag.push(prop,",",val)}bag.push(")");return bag.join("")}}compileUnary(criteria){var op=criteria[0],crit=this.compileCore(criteria[1]);if(op==="!"){return"not ("+crit+")"}throw new Error("E4003")}compileGroup(criteria){var bag=[],groupOperator,nextGroupOperator;criteria.forEach(criterion=>{if(Array.isArray(criterion)){if(bag.length>1&&groupOperator!==nextGroupOperator){throw new Error("E4019")}bag.push("("+this.compileCore(criterion)+")");groupOperator=nextGroupOperator;nextGroupOperator="and"}else{nextGroupOperator=DevExpressData.utils.isConjunctiveOperator(criterion)?"and":"or"}});return bag.join(" "+groupOperator+" ")}compileBinary(criteria){criteria=DevExpressData.utils.normalizeBinaryCriterion(criteria);var op=criteria[1],formatters=this.protocolVersion===4?this.formattersV4:this.formattersV2,formatter=formatters[op.toLowerCase()];if(!formatter){throw new Error("E4003")}var fieldName=criteria[0],value=criteria[2];return formatter(DevExpressOData.serializePropName(fieldName),op==="in"||op==="notin"?value:DevExpressOData.serializeValue(value,this.protocolVersion))}compileCore(criteria){if(!criteria||criteria.length===0){return""}if(Array.isArray(criteria[0])){return this.compileGroup(criteria)}if(DevExpressData.utils.isUnaryOperation(criteria)){return this.compileUnary(criteria)}return this.compileBinary(criteria)}formatFiltersToODataQuery(){let filters=this.filters;let query=this.compileCore(filters);return query}}var filter=Object.freeze({__proto__:null,default:SteedosFilter});let t=key=>{return key};let getMonthDays=(year,month)=>{var days,endDate,millisecond,startDate;if(month===11){return 31}millisecond=1e3*60*60*24;startDate=new Date(year,month,1);endDate=new Date(year,month+1,1);days=(endDate-startDate)/millisecond;return days};let getNextQuarterFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month<3){month=3}else if(month<6){month=6}else if(month<9){month=9}else{year++;month=0}return new Date(year,month,1)};let getLastMonthFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month===0){month=11;year--;return new Date(year,month,1)}month--;return new Date(year,month,1)};let getQuarterStartMonth=month=>{if(!month){month=(new Date).getMonth()}if(month<3){return 0}else if(month<6){return 3}else if(month<9){return 6}return 9};let getLastQuarterFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month<3){year--;month=9}else if(month<6){month=0}else if(month<9){month=3}else{month=6}return new Date(year,month,1)};let getBetweenTimeBuiltinValueItem=(key,utcOffset)=>{var currentMonth,currentYear,endValue,firstDay,label,lastDay,lastMonday,lastMonthFinalDay,lastMonthFirstDay,lastQuarterEndDay,lastQuarterStartDay,lastSunday,last_120_days,last_30_days,last_60_days,last_7_days,last_90_days,millisecond,minusDay,monday,month,nextMonday,nextMonthFinalDay,nextMonthFirstDay,nextQuarterEndDay,nextQuarterStartDay,nextSunday,nextYear,next_120_days,next_30_days,next_60_days,next_7_days,next_90_days,now,previousYear,startValue,strEndDay,strFirstDay,strLastDay,strMonday,strStartDay,strSunday,strToday,strTomorrow,strYestday,sunday,thisQuarterEndDay,thisQuarterStartDay,tomorrow,values,week,year,yestday;now=new Date;millisecond=1e3*60*60*24;yestday=new Date(now.getTime()-millisecond);tomorrow=new Date(now.getTime()+millisecond);week=now.getDay();minusDay=week!==0?week-1:6;monday=new Date(now.getTime()-minusDay*millisecond);sunday=new Date(monday.getTime()+6*millisecond);lastSunday=new Date(monday.getTime()-millisecond);lastMonday=new Date(lastSunday.getTime()-millisecond*6);nextMonday=new Date(sunday.getTime()+millisecond);nextSunday=new Date(nextMonday.getTime()+millisecond*6);currentYear=now.getFullYear();previousYear=currentYear-1;nextYear=currentYear+1;currentMonth=now.getMonth();year=now.getFullYear();month=now.getMonth();firstDay=new Date(currentYear,currentMonth,1);if(currentMonth===11){year++;month++}else{month++}nextMonthFirstDay=new Date(year,month,1);nextMonthFinalDay=new Date(year,month,getMonthDays(year,month));lastDay=new Date(nextMonthFirstDay.getTime()-millisecond);lastMonthFirstDay=getLastMonthFirstDay(currentYear,currentMonth);lastMonthFinalDay=new Date(firstDay.getTime()-millisecond);thisQuarterStartDay=new Date(currentYear,getQuarterStartMonth(currentMonth),1);thisQuarterEndDay=new Date(currentYear,getQuarterStartMonth(currentMonth)+2,getMonthDays(currentYear,getQuarterStartMonth(currentMonth)+2));lastQuarterStartDay=getLastQuarterFirstDay(currentYear,currentMonth);lastQuarterEndDay=new Date(lastQuarterStartDay.getFullYear(),lastQuarterStartDay.getMonth()+2,getMonthDays(lastQuarterStartDay.getFullYear(),lastQuarterStartDay.getMonth()+2));nextQuarterStartDay=getNextQuarterFirstDay(currentYear,currentMonth);nextQuarterEndDay=new Date(nextQuarterStartDay.getFullYear(),nextQuarterStartDay.getMonth()+2,getMonthDays(nextQuarterStartDay.getFullYear(),nextQuarterStartDay.getMonth()+2));last_7_days=new Date(now.getTime()-6*millisecond);last_30_days=new Date(now.getTime()-29*millisecond);last_60_days=new Date(now.getTime()-59*millisecond);last_90_days=new Date(now.getTime()-89*millisecond);last_120_days=new Date(now.getTime()-119*millisecond);next_7_days=new Date(now.getTime()+6*millisecond);next_30_days=new Date(now.getTime()+29*millisecond);next_60_days=new Date(now.getTime()+59*millisecond);next_90_days=new Date(now.getTime()+89*millisecond);next_120_days=new Date(now.getTime()+119*millisecond);switch(key){case"last_year":label=t("creator_filter_operation_between_last_year");startValue=new Date(previousYear+"-01-01T00:00:00Z");endValue=new Date(previousYear+"-12-31T23:59:59Z");break;case"this_year":label=t("creator_filter_operation_between_this_year");startValue=new Date(currentYear+"-01-01T00:00:00Z");endValue=new Date(currentYear+"-12-31T23:59:59Z");break;case"next_year":label=t("creator_filter_operation_between_next_year");startValue=new Date(nextYear+"-01-01T00:00:00Z");endValue=new Date(nextYear+"-12-31T23:59:59Z");break;case"last_quarter":strFirstDay=moment__default["default"](lastQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"this_quarter":strFirstDay=moment__default["default"](thisQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](thisQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"next_quarter":strFirstDay=moment__default["default"](nextQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](nextQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"last_month":strFirstDay=moment__default["default"](lastMonthFirstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastMonthFinalDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"this_month":strFirstDay=moment__default["default"](firstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"next_month":strFirstDay=moment__default["default"](nextMonthFirstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](nextMonthFinalDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"last_week":strMonday=moment__default["default"](lastMonday).format("YYYY-MM-DD");strSunday=moment__default["default"](lastSunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"this_week":strMonday=moment__default["default"](monday).format("YYYY-MM-DD");strSunday=moment__default["default"](sunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"next_week":strMonday=moment__default["default"](nextMonday).format("YYYY-MM-DD");strSunday=moment__default["default"](nextSunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"yestday":strYestday=moment__default["default"](yestday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_yestday");startValue=new Date(strYestday+"T00:00:00Z");endValue=new Date(strYestday+"T23:59:59Z");break;case"today":strToday=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_today");startValue=new Date(strToday+"T00:00:00Z");endValue=new Date(strToday+"T23:59:59Z");break;case"tomorrow":strTomorrow=moment__default["default"](tomorrow).format("YYYY-MM-DD");label=t("creator_filter_operation_between_tomorrow");startValue=new Date(strTomorrow+"T00:00:00Z");endValue=new Date(strTomorrow+"T23:59:59Z");break;case"last_7_days":strStartDay=moment__default["default"](last_7_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_7_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_30_days":strStartDay=moment__default["default"](last_30_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_30_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_60_days":strStartDay=moment__default["default"](last_60_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_60_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_90_days":strStartDay=moment__default["default"](last_90_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_90_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_120_days":strStartDay=moment__default["default"](last_120_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_120_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_7_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_7_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_7_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_30_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_30_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_30_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_60_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_60_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_60_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_90_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_90_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_90_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_120_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_120_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_120_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z")}values=[startValue,endValue];if(utcOffset){values=values.map(function(fv){if(fv){fv=new Date(fv.getTime());fv.setHours(fv.getHours()-utcOffset)}return fv})}return{label:label,key:key,values:values}};let getBetweenBuiltinValueItem=(key,utcOffset)=>{return getBetweenTimeBuiltinValueItem(key,utcOffset)};let isBetweenFilterOperation=operation=>{return operation==="between"};let checkFormula=formula=>{return typeof formula==="string"&&/\{\w+(\.\w+)?\}/.test(formula)};let prepareFormula=(formula,prefix="this")=>{var reg,rev;reg=/(\{[^{}]*\})/g;rev=formula.replace(reg,function(m,$1){return prefix+$1.replace(/\{\s*/,'["').replace(/\s*\}/,'"]').replace(/\s*\.\s*/g,'"]["')});return rev};let evaluateFormula=(formula,context)=>{if(checkFormula(formula)){formula=prepareFormula(formula);return function(){return eval(formula)}.call(context)}else{return formula}};const _evaluateFormula=evaluateFormula;const REG_FOR_ENCORD=/\;|\/|\?|\:|\@|\&|\=|\+|\$|\,|\#|\^|(\\\()|(\\\))|(\\\.)|\\|\||\[|\]|\{|\}/;const convertSpecialCharacter=str=>{if(str.indexOf("%5C(")>-1||str.indexOf("%5C)")>-1){return str}if(str.indexOf("%5C.")>-1){return str}if(str.indexOf("%5C*")>-1){return str}return str.replace(/([\^\$\(\)\*\+\?\.\\\|\[\]\{\}])/g,"\\$1")};let extendUserContext=(userContext,utcOffset)=>{if(!userContext.now){userContext.now=new Date}return userContext};let formatFiltersToDev=(filters,userContext={userId:null,spaceId:null,user:{utcOffset:0}})=>{if(lodash.isNull(filters)||lodash.isUndefined(filters)){return}let utcOffset=userContext.user?userContext.user.utcOffset:0;userContext=extendUserContext(userContext);var regDate=/^\d{4}-\d{1,2}-\d{1,2}(T|\s)\d{1,2}\:\d{1,2}(\:\d{1,2}(\.\d{1,3})?)?(Z|((\+|\-)\d{1,2}\:\d{1,2}))?$/;var filtersLooper,selector;if(!lodash.isFunction(filters)&&!filters.length){return}selector=[];filtersLooper=function(filters_loop){var builtinValue,field,i,isBetweenOperation,option,ref,sub_selector,tempFilters,tempLooperResult,value;tempFilters=[];tempLooperResult=null;if(filters_loop==="!"){return filters_loop}if(lodash.isFunction(filters_loop)){filters_loop=filters_loop()}if(!lodash.isArray(filters_loop)){if(lodash.isObject(filters_loop)){if(filters_loop.operation){filters_loop=[filters_loop.field,filters_loop.operation,filters_loop.value]}else{return null}}else{return null}}if(filters_loop.length===1){tempLooperResult=filtersLooper(filters_loop[0]);if(tempLooperResult){tempFilters.push(tempLooperResult)}}else if(filters_loop.length===2){filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}else if(filters_loop.length===3){if(lodash.includes(["or","and"],filters_loop[1])){tempFilters=[];i=0;while(i<filters_loop.length){if(lodash.includes(["or","and"],filters_loop[i])){i++;continue}tempLooperResult=filtersLooper(filters_loop[i]);if(!tempLooperResult){i++;continue}if(i>0){tempFilters.push(filters_loop[i-1])}tempFilters.push(tempLooperResult);i++}if(lodash.includes(["or","and"],tempFilters[0])){tempFilters.shift()}}else{if(lodash.isString(filters_loop[1])){field=filters_loop[0];option=filters_loop[1];value=filters_loop[2];if(lodash.isFunction(value)){value=value()}if(option==="!="){option="<>"}value=_evaluateFormula(value,userContext);sub_selector=[];isBetweenOperation=isBetweenFilterOperation(option);if(isBetweenOperation&&lodash.isString(value)){builtinValue=getBetweenBuiltinValueItem(value,utcOffset);if(builtinValue){value=builtinValue.values}}if(lodash.isArray(value)){value=value.map(function(item){if(typeof item==="string"){if(["contains","startswith","endswith","notcontains","notstartswith","notendswith"].indexOf(option)>-1){item=convertSpecialCharacter(item)}if(regDate.test(item)){item=new Date(item)}else if(REG_FOR_ENCORD.test(item)){item=encodeURIComponent(item)}}return item});if(["=","in"].indexOf(option)>-1){if(value.length){sub_selector.push([field,"in",`(${JSON.stringify(value).replace(/\"/g,"'").slice(1).slice(0,-1)})`],"and")}else{sub_selector.push([field,"=","__badQueryForEmptyArray"],"and")}}else if(["<>","notin"].indexOf(option)>-1){sub_selector.push([field,"notin",`(${JSON.stringify(value).replace(/\"/g,"'").slice(1).slice(0,-1)})`],"and")}else if(["notcontains","notstartswith","notendswith"].indexOf(option)>-1){lodash.each(value,function(v){return sub_selector.push([field,option,v],"and")})}else if(isBetweenOperation){if(value.length>0){if([null,undefined,""].indexOf(value[0])<0||[null,undefined,""].indexOf(value[1])<0){if([null,undefined,""].indexOf(value[0])<0){sub_selector.push([field,">=",value[0]],"and")}if([null,undefined,""].indexOf(value[1])<0){sub_selector.push([field,"<=",value[1]],"and")}}}}else{lodash.each(value,function(v){return sub_selector.push([field,option,v],"or")})}if(sub_selector[sub_selector.length-1]==="and"||sub_selector[sub_selector.length-1]==="or"){sub_selector.pop()}if(sub_selector.length){tempFilters=sub_selector}}else if(value===false){if(option==="="){tempFilters=[[field,"=",false],"or",[field,"=",null]]}else if(option==="<>"){tempFilters=[field,"=",true]}}else{if(isBetweenOperation&&!lodash.isArray(value));else{if(typeof value==="string"){if(["contains","startswith","endswith","notcontains","notstartswith","notendswith"].indexOf(option)>-1){value=convertSpecialCharacter(value)}if(regDate.test(value)){value=new Date(value)}else if(REG_FOR_ENCORD.test(value)){if(["in","notin"].indexOf(option)<0){value=encodeURIComponent(value)}}}tempFilters=[field,option,value]}}}else{filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}}}else{if((ref=lodash.intersection(["or","and"],filters_loop))!=null?ref.length:void 0){tempFilters=[];i=0;while(i<filters_loop.length){if(lodash.includes(["or","and"],filters_loop[i])){i++;continue}tempLooperResult=filtersLooper(filters_loop[i]);if(!tempLooperResult){i++;continue}if(i>0){tempFilters.push(filters_loop[i-1])}tempFilters.push(tempLooperResult);i++}if(lodash.includes(["or","and"],tempFilters[0])){tempFilters.shift()}}else{filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}}if(tempFilters.length){return tempFilters}else{return null}};selector=filtersLooper(filters);return selector};let formatFiltersToODataQuery=(filters,userContext,odataProtocolVersion,forceLowerCase)=>{let devFilters=formatFiltersToDev(filters,userContext);return new SteedosFilter(devFilters,odataProtocolVersion,forceLowerCase).formatFiltersToODataQuery()};const _formatFiltersToDev=formatFiltersToDev;const _formatFiltersToODataQuery=formatFiltersToODataQuery;let expandFieldName=(initial,fieldName)=>{lodash.reduce(fieldName.split("."),function(m,k){if(!m[k]){m[k]={}}return m[k]},initial);return initial};let expandFieldNames=fieldNames=>{let initial={};fieldNames.forEach(n=>{expandFieldName(initial,n)});return initial};let generateIndents=count=>{return Array(count).fill(" ").join("")};let reduceGraphqlFieldsQuery=(fields,indentsCount)=>{if(!indentsCount){indentsCount=0}let itemQuery;return` {
|
|
1
|
+
(function(global,factory){typeof exports==="object"&&typeof module!=="undefined"?factory(exports,require("lodash"),require("moment")):typeof define==="function"&&define.amd?define(["exports","lodash","moment"],factory):(global=typeof globalThis!=="undefined"?globalThis:global||self,factory(global.SteedosFilters={},global._,global.moment))})(this,function(exports,lodash,moment){function _interopDefaultLegacy(e){return e&&typeof e==="object"&&"default"in e?e:{default:e}}var moment__default=_interopDefaultLegacy(moment);function leftPad(text,length){while(text.length<length){text="0"+text}return text}var FORMAT_TYPES={3:"abbreviated",4:"wide",5:"narrow"};var LDML_FORMATTERS={y:function(date,count,useUtc){var year=date[useUtc?"getUTCFullYear":"getFullYear"]();if(count===2){year=year%100}return leftPad(year.toString(),count)},M:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getMonthNames(formatType,"format")[month]}return leftPad((month+1).toString(),Math.min(count,2))},L:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getMonthNames(formatType,"standalone")[month]}return leftPad((month+1).toString(),Math.min(count,2))},Q:function(date,count,useUtc,dateParts){var month=date[useUtc?"getUTCMonth":"getMonth"]();var quarter=Math.floor(month/3);var formatType=FORMAT_TYPES[count];if(formatType){return dateParts.getQuarterNames(formatType)[quarter]}return leftPad((quarter+1).toString(),Math.min(count,2))},E:function(date,count,useUtc,dateParts){var day=date[useUtc?"getUTCDay":"getDay"]();var formatType=FORMAT_TYPES[count<3?3:count];return dateParts.getDayNames(formatType)[day]},a:function(date,count,useUtc,dateParts){var hours=date[useUtc?"getUTCHours":"getHours"](),period=hours<12?0:1,formatType=FORMAT_TYPES[count];return dateParts.getPeriodNames(formatType)[period]},d:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCDate":"getDate"]().toString(),Math.min(count,2))},H:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCHours":"getHours"]().toString(),Math.min(count,2))},h:function(date,count,useUtc){var hours=date[useUtc?"getUTCHours":"getHours"]();return leftPad((hours%12||12).toString(),Math.min(count,2))},m:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCMinutes":"getMinutes"]().toString(),Math.min(count,2))},s:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCSeconds":"getSeconds"]().toString(),Math.min(count,2))},S:function(date,count,useUtc){return leftPad(date[useUtc?"getUTCMilliseconds":"getMilliseconds"]().toString(),3).substr(0,count)},x:function(date,count,useUtc){var timezoneOffset=useUtc?0:date.getTimezoneOffset(),signPart=timezoneOffset>0?"-":"+",timezoneOffsetAbs=Math.abs(timezoneOffset),hours=Math.floor(timezoneOffsetAbs/60),minutes=timezoneOffsetAbs%60,hoursPart=leftPad(hours.toString(),2),minutesPart=leftPad(minutes.toString(),2);return signPart+hoursPart+(count>=3?":":"")+(count>1||minutes?minutesPart:"")},X:function(date,count,useUtc){if(useUtc||!date.getTimezoneOffset()){return"Z"}return LDML_FORMATTERS.x(date,count,useUtc)},Z:function(date,count,useUtc){return LDML_FORMATTERS.X(date,count>=5?3:2,useUtc)}};var getFormatter=function(format,dateParts){return function(date){var charIndex,formatter,char,charCount=0,separator="'",isEscaping=false,isCurrentCharEqualsNext,result="";if(!date)return null;if(!format)return date;var useUtc=format[format.length-1]==="Z"||format.slice(-3)==="'Z'";for(charIndex=0;charIndex<format.length;charIndex++){char=format[charIndex];formatter=LDML_FORMATTERS[char];isCurrentCharEqualsNext=char===format[charIndex+1];charCount++;if(!isCurrentCharEqualsNext){if(formatter&&!isEscaping){result+=formatter(date,charCount,useUtc,dateParts)}charCount=0}if(char===separator&&!isCurrentCharEqualsNext){isEscaping=!isEscaping}else if(isEscaping||!formatter){result+=char}if(char===separator&&isCurrentCharEqualsNext){charIndex++}}return result}};const _getFormatter=getFormatter;var MONTHS=["January","February","March","April","May","June","July","August","September","October","November","December"],DAYS=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"],PERIODS=["AM","PM"],QUARTERS=["Q1","Q2","Q3","Q4"];var cutCaptions=function(captions,format){var lengthByFormat={abbreviated:3,short:2,narrow:1};return captions.map(function(caption){return caption.substr(0,lengthByFormat[format])})};function getMonthNames(format){return cutCaptions(MONTHS,format)}function getDayNames(format){return cutCaptions(DAYS,format)}function getQuarterNames(format){return QUARTERS}function getPeriodNames(format){return PERIODS}var defaultDateNames={getMonthNames:getMonthNames,getDayNames:getDayNames,getQuarterNames:getQuarterNames,getPeriodNames:getPeriodNames};const DevExpressData={utils:{isConjunctiveOperator:function(condition){return/^(and|&&|&)$/i.test(condition)},normalizeBinaryCriterion:function(crit){return[crit[0],crit.length<3?"=":String(crit[1]).toLowerCase(),crit.length<2?true:crit[crit.length-1]]},isUnaryOperation:function(crit){return crit[0]==="!"&&Array.isArray(crit[1])}}};const DevExpressOData={pad(text,length,right){text=String(text);while(text.length<length){text=right?text+"0":"0"+text}return text},padLeft2(text){return this.pad(text,2)},serializePropName(propName){return propName.replace(/\./g,"/")},serializeValue(value,protocolVersion){if(value===undefined){return null}switch(protocolVersion){case 2:return this.serializeValueV2(value);case 3:return this.serializeValueV2(value);case 4:return this.serializeValueV4(value);default:return this.serializeValueV4(value)}},serializeValueV2(value){if(value instanceof Date){return this.serializeDate(value)}if(typeof value==="string"){return this.serializeString(value)}return String(value)},serializeValueV4(value){if(value instanceof Date){return this.formatISO8601(value,false,false)}if(Array.isArray(value)){return"["+value.map(item=>{return this.serializeValueV4(item)}).join(",")+"]"}return this.serializeValueV2(value)},serializeString(value){return"'"+value.replace(/'/g,"''")+"'"},serializeDate(value,serializationFormat){if(!serializationFormat){return value}if(!(value instanceof Date)){return null}if(serializationFormat==="number"){return value&&value.valueOf?value.valueOf():null}return _getFormatter(serializationFormat,defaultDateNames)(value)},formatISO8601(date,skipZeroTime,skipTimezone){var bag=[];var isZeroTime=function(){return date.getUTCHours()+date.getUTCMinutes()+date.getUTCSeconds()+date.getUTCMilliseconds()<1};bag.push(date.getUTCFullYear());bag.push("-");bag.push(this.padLeft2(date.getUTCMonth()+1));bag.push("-");bag.push(this.padLeft2(date.getUTCDate()));if(!(skipZeroTime&&isZeroTime())){bag.push("T");bag.push(this.padLeft2(date.getUTCHours()));bag.push(":");bag.push(this.padLeft2(date.getUTCMinutes()));bag.push(":");bag.push(this.padLeft2(date.getUTCSeconds()));if(date.getUTCMilliseconds()){bag.push(".");bag.push(this.pad(date.getUTCMilliseconds(),3))}if(!skipTimezone){bag.push("Z")}}return bag.join("")}};class SteedosFilter{constructor(filters,odataProtocolVersion=4,forceLowerCase=true){this.filters=filters||[];this.protocolVersion=odataProtocolVersion;this.forceLowerCase=forceLowerCase;this.formatters={"=":this.createBinaryOperationFormatter("eq"),"<>":this.createBinaryOperationFormatter("ne"),">":this.createBinaryOperationFormatter("gt"),">=":this.createBinaryOperationFormatter("ge"),"<":this.createBinaryOperationFormatter("lt"),"<=":this.createBinaryOperationFormatter("le"),startswith:this.createStringFuncFormatter("startswith"),endswith:this.createStringFuncFormatter("endswith")};this.formattersV2={...this.formatters,...{contains:this.createStringFuncFormatter("substringof",true),notcontains:this.createStringFuncFormatter("not substringof",true)}};this.formattersV4={...this.formatters,...{contains:this.createStringFuncFormatter("contains"),notcontains:this.createStringFuncFormatter("not contains"),notstartswith:this.createStringFuncFormatter("not startswith"),notendswith:this.createStringFuncFormatter("not endswith"),in:this.createBinaryOperationFormatter("in"),notin:this.createBinaryOperationFormatter("notin")}}}createBinaryOperationFormatter(op){return(prop,val)=>{return prop+" "+op+" "+val}}createStringFuncFormatter(op,reverse){return(prop,val)=>{var bag=[op,"("];if(val&&this.forceLowerCase){val=val.toLowerCase()}if(reverse){bag.push(val,",",prop)}else{bag.push(prop,",",val)}bag.push(")");return bag.join("")}}compileUnary(criteria){var op=criteria[0],crit=this.compileCore(criteria[1]);if(op==="!"){return"not ("+crit+")"}throw new Error("E4003")}compileGroup(criteria){var bag=[],groupOperator,nextGroupOperator;criteria.forEach(criterion=>{if(Array.isArray(criterion)){if(bag.length>1&&groupOperator!==nextGroupOperator){throw new Error("E4019")}bag.push("("+this.compileCore(criterion)+")");groupOperator=nextGroupOperator;nextGroupOperator="and"}else{nextGroupOperator=DevExpressData.utils.isConjunctiveOperator(criterion)?"and":"or"}});return bag.join(" "+groupOperator+" ")}compileBinary(criteria){criteria=DevExpressData.utils.normalizeBinaryCriterion(criteria);var op=criteria[1],formatters=this.protocolVersion===4?this.formattersV4:this.formattersV2,formatter=formatters[op.toLowerCase()];if(!formatter){throw new Error("E4003")}var fieldName=criteria[0],value=criteria[2];return formatter(DevExpressOData.serializePropName(fieldName),op==="in"||op==="notin"?value:DevExpressOData.serializeValue(value,this.protocolVersion))}compileCore(criteria){if(!criteria||criteria.length===0){return""}if(Array.isArray(criteria[0])){return this.compileGroup(criteria)}if(DevExpressData.utils.isUnaryOperation(criteria)){return this.compileUnary(criteria)}return this.compileBinary(criteria)}formatFiltersToODataQuery(){let filters=this.filters;let query=this.compileCore(filters);return query}}var filter=Object.freeze({__proto__:null,default:SteedosFilter});let t=key=>{return key};let getMonthDays=(year,month)=>{var days,endDate,millisecond,startDate;if(month===11){return 31}millisecond=1e3*60*60*24;startDate=new Date(year,month,1);endDate=new Date(year,month+1,1);days=(endDate-startDate)/millisecond;return days};let getNextQuarterFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month<3){month=3}else if(month<6){month=6}else if(month<9){month=9}else{year++;month=0}return new Date(year,month,1)};let getLastMonthFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month===0){month=11;year--;return new Date(year,month,1)}month--;return new Date(year,month,1)};let getQuarterStartMonth=month=>{if(!month){month=(new Date).getMonth()}if(month<3){return 0}else if(month<6){return 3}else if(month<9){return 6}return 9};let getLastQuarterFirstDay=(year,month)=>{if(!year){year=(new Date).getFullYear()}if(!month){month=(new Date).getMonth()}if(month<3){year--;month=9}else if(month<6){month=0}else if(month<9){month=3}else{month=6}return new Date(year,month,1)};let getBetweenTimeBuiltinValueItem=(key,utcOffset)=>{var currentMonth,currentYear,endValue,firstDay,label,lastDay,lastMonday,lastMonthFinalDay,lastMonthFirstDay,lastQuarterEndDay,lastQuarterStartDay,lastSunday,last_120_days,last_30_days,last_60_days,last_7_days,last_90_days,millisecond,minusDay,monday,month,nextMonday,nextMonthFinalDay,nextMonthFirstDay,nextQuarterEndDay,nextQuarterStartDay,nextSunday,nextYear,next_120_days,next_30_days,next_60_days,next_7_days,next_90_days,now,previousYear,startValue,strEndDay,strFirstDay,strLastDay,strMonday,strStartDay,strSunday,strToday,strTomorrow,strYestday,sunday,thisQuarterEndDay,thisQuarterStartDay,tomorrow,values,week,year,yestday;now=new Date;millisecond=1e3*60*60*24;yestday=new Date(now.getTime()-millisecond);tomorrow=new Date(now.getTime()+millisecond);week=now.getDay();minusDay=week!==0?week-1:6;monday=new Date(now.getTime()-minusDay*millisecond);sunday=new Date(monday.getTime()+6*millisecond);lastSunday=new Date(monday.getTime()-millisecond);lastMonday=new Date(lastSunday.getTime()-millisecond*6);nextMonday=new Date(sunday.getTime()+millisecond);nextSunday=new Date(nextMonday.getTime()+millisecond*6);currentYear=now.getFullYear();previousYear=currentYear-1;nextYear=currentYear+1;currentMonth=now.getMonth();year=now.getFullYear();month=now.getMonth();firstDay=new Date(currentYear,currentMonth,1);if(currentMonth===11){year++;month++}else{month++}nextMonthFirstDay=new Date(year,month,1);nextMonthFinalDay=new Date(year,month,getMonthDays(year,month));lastDay=new Date(nextMonthFirstDay.getTime()-millisecond);lastMonthFirstDay=getLastMonthFirstDay(currentYear,currentMonth);lastMonthFinalDay=new Date(firstDay.getTime()-millisecond);thisQuarterStartDay=new Date(currentYear,getQuarterStartMonth(currentMonth),1);thisQuarterEndDay=new Date(currentYear,getQuarterStartMonth(currentMonth)+2,getMonthDays(currentYear,getQuarterStartMonth(currentMonth)+2));lastQuarterStartDay=getLastQuarterFirstDay(currentYear,currentMonth);lastQuarterEndDay=new Date(lastQuarterStartDay.getFullYear(),lastQuarterStartDay.getMonth()+2,getMonthDays(lastQuarterStartDay.getFullYear(),lastQuarterStartDay.getMonth()+2));nextQuarterStartDay=getNextQuarterFirstDay(currentYear,currentMonth);nextQuarterEndDay=new Date(nextQuarterStartDay.getFullYear(),nextQuarterStartDay.getMonth()+2,getMonthDays(nextQuarterStartDay.getFullYear(),nextQuarterStartDay.getMonth()+2));last_7_days=new Date(now.getTime()-6*millisecond);last_30_days=new Date(now.getTime()-29*millisecond);last_60_days=new Date(now.getTime()-59*millisecond);last_90_days=new Date(now.getTime()-89*millisecond);last_120_days=new Date(now.getTime()-119*millisecond);next_7_days=new Date(now.getTime()+6*millisecond);next_30_days=new Date(now.getTime()+29*millisecond);next_60_days=new Date(now.getTime()+59*millisecond);next_90_days=new Date(now.getTime()+89*millisecond);next_120_days=new Date(now.getTime()+119*millisecond);switch(key){case"last_year":label=t("creator_filter_operation_between_last_year");startValue=new Date(previousYear+"-01-01T00:00:00Z");endValue=new Date(previousYear+"-12-31T23:59:59Z");break;case"this_year":label=t("creator_filter_operation_between_this_year");startValue=new Date(currentYear+"-01-01T00:00:00Z");endValue=new Date(currentYear+"-12-31T23:59:59Z");break;case"next_year":label=t("creator_filter_operation_between_next_year");startValue=new Date(nextYear+"-01-01T00:00:00Z");endValue=new Date(nextYear+"-12-31T23:59:59Z");break;case"last_quarter":strFirstDay=moment__default["default"](lastQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"this_quarter":strFirstDay=moment__default["default"](thisQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](thisQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"next_quarter":strFirstDay=moment__default["default"](nextQuarterStartDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](nextQuarterEndDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_quarter");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"last_month":strFirstDay=moment__default["default"](lastMonthFirstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastMonthFinalDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"this_month":strFirstDay=moment__default["default"](firstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](lastDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"next_month":strFirstDay=moment__default["default"](nextMonthFirstDay).format("YYYY-MM-DD");strLastDay=moment__default["default"](nextMonthFinalDay).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_month");startValue=new Date(strFirstDay+"T00:00:00Z");endValue=new Date(strLastDay+"T23:59:59Z");break;case"last_week":strMonday=moment__default["default"](lastMonday).format("YYYY-MM-DD");strSunday=moment__default["default"](lastSunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"this_week":strMonday=moment__default["default"](monday).format("YYYY-MM-DD");strSunday=moment__default["default"](sunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_this_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"next_week":strMonday=moment__default["default"](nextMonday).format("YYYY-MM-DD");strSunday=moment__default["default"](nextSunday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_week");startValue=new Date(strMonday+"T00:00:00Z");endValue=new Date(strSunday+"T23:59:59Z");break;case"yestday":strYestday=moment__default["default"](yestday).format("YYYY-MM-DD");label=t("creator_filter_operation_between_yestday");startValue=new Date(strYestday+"T00:00:00Z");endValue=new Date(strYestday+"T23:59:59Z");break;case"today":strToday=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_today");startValue=new Date(strToday+"T00:00:00Z");endValue=new Date(strToday+"T23:59:59Z");break;case"tomorrow":strTomorrow=moment__default["default"](tomorrow).format("YYYY-MM-DD");label=t("creator_filter_operation_between_tomorrow");startValue=new Date(strTomorrow+"T00:00:00Z");endValue=new Date(strTomorrow+"T23:59:59Z");break;case"last_7_days":strStartDay=moment__default["default"](last_7_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_7_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_30_days":strStartDay=moment__default["default"](last_30_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_30_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_60_days":strStartDay=moment__default["default"](last_60_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_60_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_90_days":strStartDay=moment__default["default"](last_90_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_90_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"last_120_days":strStartDay=moment__default["default"](last_120_days).format("YYYY-MM-DD");strEndDay=moment__default["default"](now).format("YYYY-MM-DD");label=t("creator_filter_operation_between_last_120_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_7_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_7_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_7_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_30_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_30_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_30_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_60_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_60_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_60_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_90_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_90_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_90_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z");break;case"next_120_days":strStartDay=moment__default["default"](now).format("YYYY-MM-DD");strEndDay=moment__default["default"](next_120_days).format("YYYY-MM-DD");label=t("creator_filter_operation_between_next_120_days");startValue=new Date(strStartDay+"T00:00:00Z");endValue=new Date(strEndDay+"T23:59:59Z")}values=[startValue,endValue];if(utcOffset){values=values.map(function(fv){if(fv){fv=new Date(fv.getTime());fv.setHours(fv.getHours()-utcOffset)}return fv})}return{label:label,key:key,values:values}};let getBetweenBuiltinValueItem=(key,utcOffset)=>{return getBetweenTimeBuiltinValueItem(key,utcOffset)};let isBetweenFilterOperation=operation=>{return operation==="between"};let checkFormula=formula=>{return typeof formula==="string"&&/\{\w+(\.\w+)?\}/.test(formula)};let prepareFormula=(formula,prefix="this")=>{var reg,rev;reg=/(\{[^{}]*\})/g;rev=formula.replace(reg,function(m,$1){return prefix+$1.replace(/\{\s*/,'["').replace(/\s*\}/,'"]').replace(/\s*\.\s*/g,'"]["')});return rev};let evaluateFormula=(formula,context)=>{if(checkFormula(formula)){formula=prepareFormula(formula);return function(){return eval(formula)}.call(context)}else{return formula}};const _evaluateFormula=evaluateFormula;const REG_FOR_ENCORD=/\;|\/|\?|\:|\@|\&|\=|\+|\$|\,|\#|\%(?!25|3B|3b|2F|2f|3F|3f|3A|3a|40|26|3D|3d|2B|2b|24|2C|2c|23|5C|5c|5E|5e|7C|7c|5B|5b|5D|5d|7B|7b|7D|7d)|\^|(\\\()|(\\\))|(\\\.)|\\|\||\[|\]|\{|\}/;const convertSpecialCharacter=str=>{if(str.indexOf("%5C(")>-1||str.indexOf("%5C)")>-1){return str}if(str.indexOf("%5C.")>-1){return str}if(str.indexOf("%5C*")>-1){return str}return str.replace(/([\^\$\(\)\*\+\?\.\\\|\[\]\{\}])/g,"\\$1")};let extendUserContext=(userContext,utcOffset)=>{if(!userContext.now){userContext.now=new Date}return userContext};let formatFiltersToDev=(filters,userContext={userId:null,spaceId:null,user:{utcOffset:0}})=>{if(lodash.isNull(filters)||lodash.isUndefined(filters)){return}let utcOffset=userContext.user?userContext.user.utcOffset:0;userContext=extendUserContext(userContext);var regDate=/^\d{4}-\d{1,2}-\d{1,2}(T|\s)\d{1,2}\:\d{1,2}(\:\d{1,2}(\.\d{1,3})?)?(Z|((\+|\-)\d{1,2}\:\d{1,2}))?$/;var filtersLooper,selector;if(!lodash.isFunction(filters)&&!filters.length){return}selector=[];filtersLooper=function(filters_loop){var builtinValue,field,i,isBetweenOperation,option,ref,sub_selector,tempFilters,tempLooperResult,value;tempFilters=[];tempLooperResult=null;if(filters_loop==="!"){return filters_loop}if(lodash.isFunction(filters_loop)){filters_loop=filters_loop()}if(!lodash.isArray(filters_loop)){if(lodash.isObject(filters_loop)){if(filters_loop.operation){filters_loop=[filters_loop.field,filters_loop.operation,filters_loop.value]}else{return null}}else{return null}}if(filters_loop.length===1){tempLooperResult=filtersLooper(filters_loop[0]);if(tempLooperResult){tempFilters.push(tempLooperResult)}}else if(filters_loop.length===2){filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}else if(filters_loop.length===3){if(lodash.includes(["or","and"],filters_loop[1])){tempFilters=[];i=0;while(i<filters_loop.length){if(lodash.includes(["or","and"],filters_loop[i])){i++;continue}tempLooperResult=filtersLooper(filters_loop[i]);if(!tempLooperResult){i++;continue}if(i>0){tempFilters.push(filters_loop[i-1])}tempFilters.push(tempLooperResult);i++}if(lodash.includes(["or","and"],tempFilters[0])){tempFilters.shift()}}else{if(lodash.isString(filters_loop[1])){field=filters_loop[0];option=filters_loop[1];value=filters_loop[2];if(lodash.isFunction(value)){value=value()}if(option==="!="){option="<>"}value=_evaluateFormula(value,userContext);sub_selector=[];isBetweenOperation=isBetweenFilterOperation(option);if(isBetweenOperation&&lodash.isString(value)){builtinValue=getBetweenBuiltinValueItem(value,utcOffset);if(builtinValue){value=builtinValue.values}}if(lodash.isArray(value)){value=value.map(function(item){if(typeof item==="string"){if(["contains","startswith","endswith","notcontains","notstartswith","notendswith"].indexOf(option)>-1){item=convertSpecialCharacter(item)}if(regDate.test(item)){item=new Date(item)}else if(REG_FOR_ENCORD.test(item)){item=encodeURIComponent(item)}}return item});if(["=","in"].indexOf(option)>-1){if(value.length){sub_selector.push([field,"in",`(${JSON.stringify(value).replace(/\"/g,"'").slice(1).slice(0,-1)})`],"and")}else{sub_selector.push([field,"=","__badQueryForEmptyArray"],"and")}}else if(["<>","notin"].indexOf(option)>-1){sub_selector.push([field,"notin",`(${JSON.stringify(value).replace(/\"/g,"'").slice(1).slice(0,-1)})`],"and")}else if(["notcontains","notstartswith","notendswith"].indexOf(option)>-1){lodash.each(value,function(v){return sub_selector.push([field,option,v],"and")})}else if(isBetweenOperation){if(value.length>0){if([null,undefined,""].indexOf(value[0])<0||[null,undefined,""].indexOf(value[1])<0){if([null,undefined,""].indexOf(value[0])<0){sub_selector.push([field,">=",value[0]],"and")}if([null,undefined,""].indexOf(value[1])<0){sub_selector.push([field,"<=",value[1]],"and")}}}}else{lodash.each(value,function(v){return sub_selector.push([field,option,v],"or")})}if(sub_selector[sub_selector.length-1]==="and"||sub_selector[sub_selector.length-1]==="or"){sub_selector.pop()}if(sub_selector.length){tempFilters=sub_selector}}else if(value===false){if(option==="="){tempFilters=[[field,"=",false],"or",[field,"=",null]]}else if(option==="<>"){tempFilters=[field,"=",true]}}else{if(isBetweenOperation&&!lodash.isArray(value));else{if(typeof value==="string"){if(["contains","startswith","endswith","notcontains","notstartswith","notendswith"].indexOf(option)>-1){value=convertSpecialCharacter(value)}if(regDate.test(value)){value=new Date(value)}else if(REG_FOR_ENCORD.test(value)){if(["in","notin"].indexOf(option)<0){value=encodeURIComponent(value)}}}tempFilters=[field,option,value]}}}else{filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}}}else{if((ref=lodash.intersection(["or","and"],filters_loop))!=null?ref.length:void 0){tempFilters=[];i=0;while(i<filters_loop.length){if(lodash.includes(["or","and"],filters_loop[i])){i++;continue}tempLooperResult=filtersLooper(filters_loop[i]);if(!tempLooperResult){i++;continue}if(i>0){tempFilters.push(filters_loop[i-1])}tempFilters.push(tempLooperResult);i++}if(lodash.includes(["or","and"],tempFilters[0])){tempFilters.shift()}}else{filters_loop.forEach(function(n,i){tempLooperResult=filtersLooper(n);if(tempLooperResult){return tempFilters.push(tempLooperResult)}})}}if(tempFilters.length){return tempFilters}else{return null}};selector=filtersLooper(filters);return selector};let formatFiltersToODataQuery=(filters,userContext,odataProtocolVersion,forceLowerCase)=>{let devFilters=formatFiltersToDev(filters,userContext);return new SteedosFilter(devFilters,odataProtocolVersion,forceLowerCase).formatFiltersToODataQuery()};const _formatFiltersToDev=formatFiltersToDev;const _formatFiltersToODataQuery=formatFiltersToODataQuery;let expandFieldName=(initial,fieldName)=>{lodash.reduce(fieldName.split("."),function(m,k){if(!m[k]){m[k]={}}return m[k]},initial);return initial};let expandFieldNames=fieldNames=>{let initial={};fieldNames.forEach(n=>{expandFieldName(initial,n)});return initial};let generateIndents=count=>{return Array(count).fill(" ").join("")};let reduceGraphqlFieldsQuery=(fields,indentsCount)=>{if(!indentsCount){indentsCount=0}let itemQuery;return` {
|
|
2
2
|
${lodash.map(fields,(fieldValue,fieldKey)=>{itemQuery=generateIndents(indentsCount)+generateIndents(1)+fieldKey;if(lodash.isEmpty(fieldValue)){itemQuery+="\n"}else{indentsCount+=1;itemQuery+=reduceGraphqlFieldsQuery(fieldValue,indentsCount);indentsCount-=1}return itemQuery}).join("")}${generateIndents(indentsCount)}}
|
|
3
3
|
`};let formatFieldsToGraphqlQuery=fields=>{if(lodash.isString(fields)){fields=fields.split(",")}let expandedFields=expandFieldNames(fields);return reduceGraphqlFieldsQuery(expandedFields,3)};let formatFiltersToGraphqlQuery=(objectName,filters,fields,userContext,odataProtocolVersion,forceLowerCase)=>{if(!lodash.isString(filters)){filters=_formatFiltersToODataQuery(filters,userContext,odataProtocolVersion,forceLowerCase)}let filtersWrap=filters?`(filters:"${filters}")`:"";let graphqlFields=formatFieldsToGraphqlQuery(fields);let graphqlQuery=`
|
|
4
4
|
query {
|
package/lib/filter.js
CHANGED
|
@@ -93,7 +93,7 @@ var DevExpressOData = {
|
|
|
93
93
|
return this.serializeValueV2(value);
|
|
94
94
|
},
|
|
95
95
|
serializeString: function serializeString(value) {
|
|
96
|
-
return "'" + value.replace(/'/g, "''")
|
|
96
|
+
return "'" + value.replace(/'/g, "''") + "'";
|
|
97
97
|
},
|
|
98
98
|
serializeDate: function serializeDate(value, serializationFormat) {
|
|
99
99
|
if (!serializationFormat) {
|
|
@@ -179,7 +179,7 @@ var SteedosFilter = /*#__PURE__*/function () {
|
|
|
179
179
|
var _this2 = this;
|
|
180
180
|
return function (prop, val) {
|
|
181
181
|
var bag = [op, "("];
|
|
182
|
-
if (_this2.forceLowerCase) {
|
|
182
|
+
if (val && _this2.forceLowerCase) {
|
|
183
183
|
// prop = prop.indexOf("tolower(") === -1 ? "tolower(" + prop + ")" : prop;
|
|
184
184
|
// forceLowerCase时不需要在prop外面增加tolower(..),因为odata-v4-mongodb等包不支持
|
|
185
185
|
val = val.toLowerCase();
|
package/lib/format.js
CHANGED
|
@@ -9,12 +9,14 @@ var _filter = _interopRequireDefault(require("./filter"));
|
|
|
9
9
|
var _lodash = require("lodash");
|
|
10
10
|
var _utils = require("./utils");
|
|
11
11
|
var _formula = require("./formula");
|
|
12
|
-
// 正则包括encodeURIComponent函数编码的
|
|
12
|
+
// 正则包括encodeURIComponent函数编码的12个特殊符号;/?:@&=+$,#%
|
|
13
13
|
// 还包括convertSpecialCharacter函数中转义的特殊符号^$()*+?.\|[]{}
|
|
14
14
|
// 注意encodeURIComponent("\\(")的结果是%5C(,需要特别处理
|
|
15
15
|
// 注意encodeURIComponent("\\.")的结果是%5C.,需要特别处理
|
|
16
16
|
// 注意encodeURIComponent("\\*")的结果是%5C*,因为不需要encodeURIComponent函数编码,所以不用加入REG_FOR_ENCORD变量
|
|
17
|
-
|
|
17
|
+
// %号很特别,\%(?!25)表示包含%且%后续不跟随25,即不匹配%25,其他特殊字符比如?执行encodeURIComponent后也包含%,所以特殊字符都需要处理
|
|
18
|
+
// 因为注意encodeURIComponent("%")结果为%25,它本身也包含了%号,即encodeURIComponent("%25")结果为%2525,所以需要排除%25这种字符串,让它不会再次执行encodeURIComponent
|
|
19
|
+
var REG_FOR_ENCORD = /\;|\/|\?|\:|\@|\&|\=|\+|\$|\,|\#|\%(?!25|3B|3b|2F|2f|3F|3f|3A|3a|40|26|3D|3d|2B|2b|24|2C|2c|23|5C|5c|5E|5e|7C|7c|5B|5b|5D|5d|7B|7b|7D|7d)|\^|(\\\()|(\\\))|(\\\.)|\\|\||\[|\]|\{|\}/;
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
^$()*+?.\|[]{}等特殊符号需要转义,否则有可能会报错且无法正确识别
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@steedos/filters",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "2.4.0
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"description": "filters lib for steedos",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"files": [
|
|
@@ -36,5 +36,5 @@
|
|
|
36
36
|
"publishConfig": {
|
|
37
37
|
"access": "public"
|
|
38
38
|
},
|
|
39
|
-
"gitHead": "
|
|
39
|
+
"gitHead": "70a4e7417d8d86c47cf5c7e3bbe0e89f2cee4222"
|
|
40
40
|
}
|