@servicetitan/data-query 31.2.0 → 32.0.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/accessor.js +7 -7
- package/dist/accessor.js.map +1 -1
- package/dist/array.operators.js +22 -23
- package/dist/array.operators.js.map +1 -1
- package/dist/common.interfaces.js +4 -1
- package/dist/common.interfaces.js.map +1 -1
- package/dist/data-result.interface.js +4 -1
- package/dist/data-result.interface.js.map +1 -1
- package/dist/data-source/async-data-source.js +28 -36
- package/dist/data-source/async-data-source.js.map +1 -1
- package/dist/data-source/data-source.js +2 -1
- package/dist/data-source/data-source.js.map +1 -1
- package/dist/data-source/in-memory-data-source.js +47 -50
- package/dist/data-source/in-memory-data-source.js.map +1 -1
- package/dist/data-source/index.js +2 -0
- package/dist/data-source/index.js.map +1 -1
- package/dist/filter-serialization.common.js +33 -43
- package/dist/filter-serialization.common.js.map +1 -1
- package/dist/filtering/filter-descriptor.interface.js +2 -2
- package/dist/filtering/filter-descriptor.interface.js.map +1 -1
- package/dist/filtering/filter-expression.factory.js +7 -8
- package/dist/filtering/filter-expression.factory.js.map +1 -1
- package/dist/filtering/filter-no-eval.js +42 -50
- package/dist/filtering/filter-no-eval.js.map +1 -1
- package/dist/filtering/filter.operators.js +42 -40
- package/dist/filtering/filter.operators.js.map +1 -1
- package/dist/funcs.js +5 -8
- package/dist/funcs.js.map +1 -1
- package/dist/grouping/aggregate.operators.js +4 -4
- package/dist/grouping/aggregate.operators.js.map +1 -1
- package/dist/grouping/group-descriptor.interface.js +4 -2
- package/dist/grouping/group-descriptor.interface.js.map +1 -1
- package/dist/grouping/group.operators.js +13 -12
- package/dist/grouping/group.operators.js.map +1 -1
- package/dist/index.js +13 -6
- package/dist/index.js.map +1 -1
- package/dist/mvc/deserialization.js +30 -31
- package/dist/mvc/deserialization.js.map +1 -1
- package/dist/mvc/operators.js +66 -48
- package/dist/mvc/operators.js.map +1 -1
- package/dist/odata-filtering.operators.js +68 -38
- package/dist/odata-filtering.operators.js.map +1 -1
- package/dist/odata.operators.js +12 -17
- package/dist/odata.operators.js.map +1 -1
- package/dist/sort-descriptor.js +4 -1
- package/dist/sort-descriptor.js.map +1 -1
- package/dist/sorting/sort-array.operator.js +10 -13
- package/dist/sorting/sort-array.operator.js.map +1 -1
- package/dist/sorting/sort.js +9 -10
- package/dist/sorting/sort.js.map +1 -1
- package/dist/state.js +4 -1
- package/dist/state.js.map +1 -1
- package/dist/transducers.js +93 -102
- package/dist/transducers.js.map +1 -1
- package/dist/utils.js +11 -20
- package/dist/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -8,63 +8,53 @@ import { isString, isDate } from './utils';
|
|
|
8
8
|
* //ignoreCase=true -> tolower(${field})`
|
|
9
9
|
* //ignoreCase=false -> ${field}`
|
|
10
10
|
* ```
|
|
11
|
-
*/
|
|
12
|
-
export const wrapIf = predicate => (str, ...args) => predicate() ? `${str[0]}${args[0]}${str[1]}` : args[0];
|
|
11
|
+
*/ export const wrapIf = (predicate)=>(str, ...args)=>predicate() ? `${str[0]}${args[0]}${str[1]}` : args[0];
|
|
13
12
|
/**
|
|
14
13
|
* @hidden
|
|
15
|
-
*/
|
|
16
|
-
export const toUTC = (date) => new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
|
|
14
|
+
*/ export const toUTC = (date)=>new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));
|
|
17
15
|
/**
|
|
18
16
|
* @hidden
|
|
19
|
-
*/
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
});
|
|
17
|
+
*/ export const quote = ({ field, value, ignoreCase, operator })=>({
|
|
18
|
+
value: `'${value.replace(/'/g, "''")}'`,
|
|
19
|
+
field,
|
|
20
|
+
ignoreCase,
|
|
21
|
+
operator
|
|
22
|
+
});
|
|
26
23
|
/**
|
|
27
24
|
* @hidden
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
});
|
|
25
|
+
*/ export const encodeValue = ({ field, value, ignoreCase, operator })=>({
|
|
26
|
+
value: `${encodeURIComponent(value)}`,
|
|
27
|
+
field,
|
|
28
|
+
ignoreCase,
|
|
29
|
+
operator
|
|
30
|
+
});
|
|
35
31
|
/**
|
|
36
32
|
* @hidden
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
});
|
|
33
|
+
*/ export const toLower = ({ field, value, ignoreCase, operator })=>({
|
|
34
|
+
field: wrapIf(()=>ignoreCase)`tolower(${field})`,
|
|
35
|
+
value,
|
|
36
|
+
ignoreCase,
|
|
37
|
+
operator
|
|
38
|
+
});
|
|
44
39
|
/**
|
|
45
40
|
* @hidden
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
});
|
|
41
|
+
*/ export const normalizeField = ({ field, value, ignoreCase, operator })=>({
|
|
42
|
+
value,
|
|
43
|
+
field: field.replace(/\./g, "/"),
|
|
44
|
+
ignoreCase,
|
|
45
|
+
operator
|
|
46
|
+
});
|
|
53
47
|
/**
|
|
54
48
|
* @hidden
|
|
55
|
-
*/
|
|
56
|
-
export const isStringValue = x => isString(x.value);
|
|
49
|
+
*/ export const isStringValue = (x)=>isString(x.value);
|
|
57
50
|
/**
|
|
58
51
|
* @hidden
|
|
59
|
-
*/
|
|
60
|
-
export const isDateValue = x => isDate(x.value);
|
|
52
|
+
*/ export const isDateValue = (x)=>isDate(x.value);
|
|
61
53
|
/**
|
|
62
54
|
* @hidden
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
.join(join(filter))})`;
|
|
69
|
-
};
|
|
55
|
+
*/ export const serializeFilters = (map, join)=>(filter)=>{
|
|
56
|
+
const brackets = wrapIf(()=>filter.filters.length > 1);
|
|
57
|
+
return brackets`(${filter.filters.map(map).join(join(filter))})`;
|
|
58
|
+
};
|
|
59
|
+
|
|
70
60
|
//# sourceMappingURL=filter-serialization.common.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/filter-serialization.common.ts"],"sourcesContent":["import { FilterDescriptor, CompositeFilterDescriptor } from './filtering/filter-descriptor.interface';\nimport { isString, isDate } from './utils';\n\n/**\n * @hidden\n */\nexport type Transformation = (x: FilterDescriptor) => FilterDescriptor;\n\n/**\n * @hidden\n * Creates a single arity function which wraps the value based on the provided predicate.\n * @example\n * ```\n * wrapIf(() => ignoreCase) `tolower(${field})`\n * //ignoreCase=true -> tolower(${field})`\n * //ignoreCase=false -> ${field}`\n * ```\n */\nexport const wrapIf = predicate => (str, ...args) => predicate() ? `${str[0]}${args[0]}${str[1]}` : args[0];\n\n/**\n * @hidden\n */\nexport const toUTC = (date: Date) =>\n new Date(Date.UTC(\n date.getFullYear(),\n date.getMonth(),\n date.getDate(),\n date.getHours(),\n date.getMinutes(),\n date.getSeconds(),\n date.getMilliseconds()\n ));\n\n/**\n * @hidden\n */\nexport const quote: Transformation = ({ field, value, ignoreCase, operator }) => ({\n value: `'${value.replace(/'/g, \"''\")}'`,\n field,\n ignoreCase,\n operator\n});\n\n/**\n * @hidden\n */\nexport const encodeValue: Transformation = ({ field, value, ignoreCase, operator }) => ({\n value: `${encodeURIComponent(value)}`,\n field,\n ignoreCase,\n operator\n});\n\n/**\n * @hidden\n */\nexport const toLower: Transformation = ({ field, value, ignoreCase, operator }) => ({\n field: wrapIf(() => ignoreCase)`tolower(${field})`,\n value,\n ignoreCase,\n operator\n});\n\n/**\n * @hidden\n */\nexport const normalizeField: Transformation = ({ field, value, ignoreCase, operator }) => ({\n value,\n field: (<string>field).replace(/\\./g, \"/\"),\n ignoreCase,\n operator\n});\n\n/**\n * @hidden\n */\nexport const isStringValue = x => isString(x.value);\n/**\n * @hidden\n */\nexport const isDateValue = x => isDate(x.value);\n\n/**\n * @hidden\n */\nexport const serializeFilters = (map, join) => (filter: CompositeFilterDescriptor): string => {\n const brackets = wrapIf(() => filter.filters.length > 1);\n return brackets`(${\n filter.filters\n .map(map)\n .join(join(filter))\n })`;\n};\n"],"names":["isString","isDate","wrapIf","predicate","str","args","toUTC","date","Date","UTC","getFullYear","getMonth","getDate","getHours","getMinutes","getSeconds","getMilliseconds","quote","field","value","ignoreCase","operator","replace","encodeValue","encodeURIComponent","toLower","normalizeField","isStringValue","x","isDateValue","serializeFilters","map","join","filter","brackets","filters","length"],"mappings":"AACA,SAASA,QAAQ,EAAEC,MAAM,QAAQ,UAAU;AAO3C;;;;;;;;;CASC,GACD,OAAO,MAAMC,SAASC,CAAAA,YAAa,CAACC,KAAK,GAAGC,OAASF,cAAc,GAAGC,GAAG,CAAC,EAAE,GAAGC,IAAI,CAAC,EAAE,GAAGD,GAAG,CAAC,EAAE,EAAE,GAAGC,IAAI,CAAC,EAAE,CAAC;AAE5G;;CAEC,GACD,OAAO,MAAMC,QAAQ,CAACC,OAClB,IAAIC,KAAKA,KAAKC,GAAG,CACbF,KAAKG,WAAW,IAChBH,KAAKI,QAAQ,IACbJ,KAAKK,OAAO,IACZL,KAAKM,QAAQ,IACbN,KAAKO,UAAU,IACfP,KAAKQ,UAAU,IACfR,KAAKS,eAAe,KACrB;AAEP;;CAEC,GACD,OAAO,MAAMC,QAAwB,CAAC,EAAEC,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAM,CAAA;QAC9EF,OAAO,CAAC,CAAC,EAAEA,MAAMG,OAAO,CAAC,MAAM,MAAM,CAAC,CAAC;QACvCJ;QACAE;QACAC;IACJ,CAAA,EAAG;AAEH;;CAEC,GACD,OAAO,MAAME,cAA8B,CAAC,EAAEL,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAM,CAAA;QACpFF,OAAO,GAAGK,mBAAmBL,QAAQ;QACrCD;QACAE;QACAC;IACJ,CAAA,EAAG;AAEH;;CAEC,GACD,OAAO,MAAMI,UAA0B,CAAC,EAAEP,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAM,CAAA;QAChFH,OAAOhB,OAAO,IAAMkB,WAAW,CAAC,QAAQ,EAAEF,MAAM,CAAC,CAAC;QAClDC;QACAC;QACAC;IACJ,CAAA,EAAG;AAEH;;CAEC,GACD,OAAO,MAAMK,iBAAiC,CAAC,EAAER,KAAK,EAAEC,KAAK,EAAEC,UAAU,EAAEC,QAAQ,EAAE,GAAM,CAAA;QACvFF;QACAD,OAAO,AAASA,MAAOI,OAAO,CAAC,OAAO;QACtCF;QACAC;IACJ,CAAA,EAAG;AAEH;;CAEC,GACD,OAAO,MAAMM,gBAAgBC,CAAAA,IAAK5B,SAAS4B,EAAET,KAAK,EAAE;AACpD;;CAEC,GACD,OAAO,MAAMU,cAAcD,CAAAA,IAAK3B,OAAO2B,EAAET,KAAK,EAAE;AAEhD;;CAEC,GACD,OAAO,MAAMW,mBAAmB,CAACC,KAAKC,OAAS,CAACC;QAC5C,MAAMC,WAAWhC,OAAO,IAAM+B,OAAOE,OAAO,CAACC,MAAM,GAAG;QACtD,OAAOF,QAAQ,CAAC,CAAC,EACbD,OAAOE,OAAO,CACTJ,GAAG,CAACA,KACJC,IAAI,CAACA,KAAKC,SACd,CAAC,CAAC;IACX,EAAE"}
|
|
@@ -3,8 +3,8 @@ import { isPresent } from '../utils';
|
|
|
3
3
|
/**
|
|
4
4
|
* @hidden
|
|
5
5
|
* Type guard for `CompositeFilterDescriptor`.
|
|
6
|
-
*/
|
|
7
|
-
export const isCompositeFilterDescriptor = (source) => {
|
|
6
|
+
*/ export const isCompositeFilterDescriptor = (source)=>{
|
|
8
7
|
return isPresent(source.filters);
|
|
9
8
|
};
|
|
9
|
+
|
|
10
10
|
//# sourceMappingURL=filter-descriptor.interface.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/filtering/filter-descriptor.interface.ts"],"sourcesContent":["import { isPresent } from '../utils';\n\n// tslint:disable:max-line-length\n/**\n * A basic filter expression. Usually is a part of [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}).\n *\n * For more information on filtering the provided data array, refer to the [`filterBy`]({% slug api_kendo-data-query_filterby %}) method.\n * For examples on using the `FilterDescriptor`, refer to the [documentation on filtering the Grid]({% slug filtering_grid %}).\n */\nexport interface FilterDescriptor {\n /**\n * The data item field to which the filter operator is applied.\n */\n field?: string | Function;\n /**\n * The filter operator (comparison).\n *\n * The supported operators are:\n * * `\"eq\"` (equal to)\n * * `\"neq\"` (not equal to)\n * * `\"isnull\"` (is equal to null)\n * * `\"isnotnull\"` (is not equal to null)\n * * `\"lt\"` (less than)\n * * `\"lte\"` (less than or equal to)\n * * `\"gt\"` (greater than)\n * * `\"gte\"` (greater than or equal to)\n *\n * The following operators are supported for string fields only:\n * * `\"startswith\"`\n * * `\"endswith\"`\n * * `\"contains\"`\n * * `\"doesnotcontain\"`\n * * `\"isempty\"`\n * * `\"isnotempty\"`\n */\n operator: string | Function;\n /**\n * The value to which the field is compared. Has to be of the same type as the field.\n */\n value?: any;\n /**\n * Determines if the string comparison is case-insensitive.\n */\n ignoreCase?: boolean;\n}\n\n/**\n * A complex filter expression. For more information, refer to the [`filterBy`]({% slug api_kendo-data-query_filterby %}) method.\n */\nexport interface CompositeFilterDescriptor {\n /**\n * The logical operation to use when the `filter.filters` option is set.\n *\n * The supported values are:\n * * `\"and\"`\n * * `\"or\"`\n */\n logic: 'or' | 'and';\n /**\n * The nested filter expressions—either [`FilterDescriptor`]({% slug api_kendo-data-query_filterdescriptor %}), or [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}). Supports the same options as `filter`. You can nest filters indefinitely.\n */\n filters: Array<FilterDescriptor | CompositeFilterDescriptor>;\n}\n// tslint:enable:max-line-length\n\n/**\n * @hidden\n * Type guard for `CompositeFilterDescriptor`.\n */\nexport const isCompositeFilterDescriptor = (source: CompositeFilterDescriptor | FilterDescriptor): source is CompositeFilterDescriptor => {\n return isPresent((<CompositeFilterDescriptor>source).filters);\n};\n"],"names":["isPresent","isCompositeFilterDescriptor","source","filters"],"mappings":"AAAA,SAASA,SAAS,QAAQ,WAAW;AA+DrC,gCAAgC;AAEhC;;;CAGC,GACD,OAAO,MAAMC,8BAA8B,CAACC;IACxC,OAAOF,UAAU,AAA4BE,OAAQC,OAAO;AAChE,EAAE"}
|
|
@@ -18,11 +18,10 @@ import { transformCompositeFilter } from "./filter-no-eval";
|
|
|
18
18
|
* const result = data.filter(predicate);
|
|
19
19
|
*
|
|
20
20
|
* ```
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
export const compileFilter = (descriptor, preprocessors = {}) => {
|
|
21
|
+
*/ // tslint:enable:max-line-length
|
|
22
|
+
export const compileFilter = (descriptor, preprocessors = {})=>{
|
|
24
23
|
if (!descriptor || descriptor.filters.length === 0) {
|
|
25
|
-
return ()
|
|
24
|
+
return ()=>true;
|
|
26
25
|
}
|
|
27
26
|
return transformCompositeFilter(descriptor, preprocessors);
|
|
28
27
|
};
|
|
@@ -55,12 +54,12 @@ export const compileFilter = (descriptor, preprocessors = {}) => {
|
|
|
55
54
|
* // output:
|
|
56
55
|
* // [{ "name": "Pork", "category": "Food", "subcategory": "Meat" }]
|
|
57
56
|
* ```
|
|
58
|
-
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
if (!isPresent(descriptor) || (isCompositeFilterDescriptor(descriptor) && descriptor.filters.length === 0)) {
|
|
57
|
+
*/ // tslint:enable:max-line-length
|
|
58
|
+
export const filterBy = (data, descriptor, preprocessors = {})=>{
|
|
59
|
+
if (!isPresent(descriptor) || isCompositeFilterDescriptor(descriptor) && descriptor.filters.length === 0) {
|
|
62
60
|
return data;
|
|
63
61
|
}
|
|
64
62
|
return data.filter(compileFilter(normalizeFilters(descriptor), preprocessors));
|
|
65
63
|
};
|
|
64
|
+
|
|
66
65
|
//# sourceMappingURL=filter-expression.factory.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/filtering/filter-expression.factory.ts"],"sourcesContent":["import { isPresent } from '../utils';\nimport { CompositeFilterDescriptor, FilterDescriptor, isCompositeFilterDescriptor } from './filter-descriptor.interface';\nimport { normalizeFilters } from './filter.operators';\nimport { Predicate, Preprocessors } from '../common.interfaces';\nimport { transformCompositeFilter } from \"./filter-no-eval\";\n\n// tslint:disable:max-line-length\n/**\n * Creates a [`Predicate`]({% slug api_kendo-data-query_predicate %}) function for the specified [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}).\n *\n * @param {CompositeFilterDescriptor} descriptor - The descriptor for which the predicate is created.\n * @returns {Predicate} - The created function instance.\n *\n * @example\n * ```ts-no-run\n * import { compileFilter } from '@progress/kendo-data-query';\n *\n * const data = [{ name: \"Pork\" }, { name: \"Pepper\" }, { name: \"Beef\" } ];\n * const predicate = compileFilter({ logic: \"and\", filters: [{ field: \"name\", operator: \"startswith\", value: \"P\" }] });\n * const result = data.filter(predicate);\n *\n * ```\n */\n// tslint:enable:max-line-length\nexport const compileFilter = <T>(descriptor: CompositeFilterDescriptor, preprocessors: Preprocessors<T> = {}): Predicate => {\n if (!descriptor || descriptor.filters.length === 0) {\n return () => true;\n }\n return transformCompositeFilter(descriptor, preprocessors);\n};\n\n// tslint:disable:max-line-length\n/**\n * Filters the provided array according to the specified [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}).\n *\n * @param {T[]} data - The data that will be filtered.\n * @param {(CompositeFilterDescriptor | FilterDescriptor)} descriptor - The filter criteria that will be applied.\n * @returns {T[]} - The filtered data.\n *\n * @example\n * ```ts-no-run\n * import { filterBy } from '@progress/kendo-data-query';\n *\n * const data = [\n * { name: \"Pork\", category: \"Food\", subcategory: \"Meat\" },\n * { name: \"Pepper\", category: \"Food\", subcategory: \"Vegetables\" },\n * { name: \"Beef\", category: \"Food\", subcategory: \"Meat\" }\n * ];\n *\n * const result = filterBy(data, {\n * logic: 'and',\n * filters: [\n * { field: \"name\", operator: \"startswith\", value: \"p\", ignoreCase: true },\n * { field: \"subcategory\", operator: \"eq\", value: \"Meat\" },\n * ]\n * });\n *\n * // output:\n * // [{ \"name\": \"Pork\", \"category\": \"Food\", \"subcategory\": \"Meat\" }]\n * ```\n */\n// tslint:enable:max-line-length\nexport const filterBy = <T>(data: T[], descriptor: CompositeFilterDescriptor | FilterDescriptor, preprocessors: Preprocessors<T> = {}): T[] => {\n if (!isPresent(descriptor) || (isCompositeFilterDescriptor(descriptor) && descriptor.filters.length === 0)) {\n return data;\n }\n\n return data.filter(compileFilter(normalizeFilters(descriptor), preprocessors));\n};\n"],"names":["isPresent","isCompositeFilterDescriptor","normalizeFilters","transformCompositeFilter","compileFilter","descriptor","preprocessors","filters","length","filterBy","data","filter"],"mappings":"AAAA,SAASA,SAAS,QAAQ,WAAW;AACrC,SAAsDC,2BAA2B,QAAQ,gCAAgC;AACzH,SAASC,gBAAgB,QAAQ,qBAAqB;AAEtD,SAASC,wBAAwB,QAAQ,mBAAmB;AAE5D,iCAAiC;AACjC;;;;;;;;;;;;;;;CAeC,GACD,gCAAgC;AAChC,OAAO,MAAMC,gBAAgB,CAAIC,YAAuCC,gBAAkC,CAAC,CAAC;IACxG,IAAI,CAACD,cAAcA,WAAWE,OAAO,CAACC,MAAM,KAAK,GAAG;QAChD,OAAO,IAAM;IACjB;IACA,OAAOL,yBAAyBE,YAAYC;AAChD,EAAE;AAEF,iCAAiC;AACjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BC,GACD,gCAAgC;AAChC,OAAO,MAAMG,WAAW,CAAIC,MAAWL,YAA0DC,gBAAkC,CAAC,CAAC;IACjI,IAAI,CAACN,UAAUK,eAAgBJ,4BAA4BI,eAAeA,WAAWE,OAAO,CAACC,MAAM,KAAK,GAAI;QACxG,OAAOE;IACX;IAEA,OAAOA,KAAKC,MAAM,CAACP,cAAcF,iBAAiBG,aAAaC;AACnE,EAAE"}
|
|
@@ -3,56 +3,53 @@ import { getter } from "../accessor";
|
|
|
3
3
|
import { isFunction, isPresent, isDate, isString, isBlank, isNumeric, isArray } from "../utils";
|
|
4
4
|
const logic = {
|
|
5
5
|
"or": {
|
|
6
|
-
concat: (acc, fn)
|
|
7
|
-
identity: ()
|
|
6
|
+
concat: (acc, fn)=>(a)=>acc(a) || fn(a),
|
|
7
|
+
identity: ()=>false
|
|
8
8
|
},
|
|
9
9
|
"and": {
|
|
10
|
-
concat: (acc, fn)
|
|
11
|
-
identity: ()
|
|
10
|
+
concat: (acc, fn)=>(a)=>acc(a) && fn(a),
|
|
11
|
+
identity: ()=>true
|
|
12
12
|
}
|
|
13
13
|
};
|
|
14
14
|
const operatorsMap = {
|
|
15
|
-
contains: (a, b)
|
|
16
|
-
doesnotcontain: (a, b)
|
|
17
|
-
doesnotendwith: (a, b)
|
|
18
|
-
doesnotstartwith: (a, b)
|
|
19
|
-
endswith: (a, b)
|
|
20
|
-
eq: (a, b)
|
|
21
|
-
gt: (a, b)
|
|
22
|
-
gte: (a, b)
|
|
23
|
-
isempty: (a)
|
|
24
|
-
isnotempty: (a)
|
|
25
|
-
isnotnull: (a)
|
|
26
|
-
isnull: (a)
|
|
27
|
-
lt: (a, b)
|
|
28
|
-
lte: (a, b)
|
|
29
|
-
neq: (a, b)
|
|
30
|
-
startswith: (a, b)
|
|
31
|
-
in: (a, b)
|
|
32
|
-
notin: (a, b)
|
|
33
|
-
isinteger: (a)
|
|
34
|
-
isfractional: (a)
|
|
15
|
+
contains: (a, b)=>(a || "").indexOf(b) >= 0,
|
|
16
|
+
doesnotcontain: (a, b)=>(a || "").indexOf(b) === -1,
|
|
17
|
+
doesnotendwith: (a, b)=>(a || "").indexOf(b, (a || "").length - (b || "").length) < 0,
|
|
18
|
+
doesnotstartwith: (a, b)=>(a || "").lastIndexOf(b, 0) === -1,
|
|
19
|
+
endswith: (a, b)=>(a || "").indexOf(b, (a || "").length - (b || "").length) >= 0,
|
|
20
|
+
eq: (a, b)=>a === b,
|
|
21
|
+
gt: (a, b)=>a > b,
|
|
22
|
+
gte: (a, b)=>a >= b,
|
|
23
|
+
isempty: (a)=>isBlank(a) || a === '',
|
|
24
|
+
isnotempty: (a)=>isPresent(a) && a !== '',
|
|
25
|
+
isnotnull: (a)=>isPresent(a),
|
|
26
|
+
isnull: (a)=>isBlank(a),
|
|
27
|
+
lt: (a, b)=>a < b,
|
|
28
|
+
lte: (a, b)=>a <= b,
|
|
29
|
+
neq: (a, b)=>a != b,
|
|
30
|
+
startswith: (a, b)=>(a || "").lastIndexOf(b, 0) === 0,
|
|
31
|
+
in: (a, b)=>b.includes(a),
|
|
32
|
+
notin: (a, b)=>!b.includes(a),
|
|
33
|
+
isinteger: (a)=>isNumeric(a) && Math.round(a) === a,
|
|
34
|
+
isfractional: (a)=>isNumeric(a) && Math.round(a) !== a
|
|
35
35
|
};
|
|
36
36
|
const dateRegExp = /^\/Date\((.*?)\)\/$/;
|
|
37
|
-
const convertValue = (value, ignoreCase)
|
|
37
|
+
const convertValue = (value, ignoreCase)=>{
|
|
38
38
|
if (value != null && isString(value)) {
|
|
39
39
|
const date = dateRegExp.exec(value);
|
|
40
40
|
if (date) {
|
|
41
41
|
return new Date(+date[1]).getTime();
|
|
42
|
-
}
|
|
43
|
-
else if (ignoreCase) {
|
|
42
|
+
} else if (ignoreCase) {
|
|
44
43
|
return value.toLowerCase();
|
|
45
44
|
}
|
|
46
|
-
}
|
|
47
|
-
else if (value != null && isDate(value)) {
|
|
45
|
+
} else if (value != null && isDate(value)) {
|
|
48
46
|
return value.getTime();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return value.map(v => isString(v) ? v.toLowerCase() : v);
|
|
47
|
+
} else if (value != null && isArray(value)) {
|
|
48
|
+
return value.map((v)=>isString(v) ? v.toLowerCase() : v);
|
|
52
49
|
}
|
|
53
50
|
return value;
|
|
54
51
|
};
|
|
55
|
-
const typedGetter = (prop, value, ignoreCase)
|
|
52
|
+
const typedGetter = (prop, value, ignoreCase)=>{
|
|
56
53
|
if (!isPresent(value)) {
|
|
57
54
|
return prop;
|
|
58
55
|
}
|
|
@@ -61,53 +58,48 @@ const typedGetter = (prop, value, ignoreCase) => {
|
|
|
61
58
|
const date = dateRegExp.exec(value);
|
|
62
59
|
if (date) {
|
|
63
60
|
value = new Date(+date[1]);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
acc = a => {
|
|
61
|
+
} else {
|
|
62
|
+
acc = (a)=>{
|
|
67
63
|
const x = prop(a);
|
|
68
64
|
if (typeof x === 'string' && ignoreCase) {
|
|
69
65
|
return x.toLowerCase();
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
66
|
+
} else {
|
|
72
67
|
return isNumeric(x) ? x + "" : x;
|
|
73
68
|
}
|
|
74
69
|
};
|
|
75
70
|
}
|
|
76
71
|
}
|
|
77
72
|
if (isDate(value)) {
|
|
78
|
-
return a
|
|
73
|
+
return (a)=>{
|
|
79
74
|
const x = acc(a);
|
|
80
75
|
return isDate(x) ? x.getTime() : x;
|
|
81
76
|
};
|
|
82
77
|
}
|
|
83
78
|
if (isArray(value) && ignoreCase) {
|
|
84
|
-
acc = a
|
|
79
|
+
acc = (a)=>{
|
|
85
80
|
const x = prop(a);
|
|
86
81
|
return isString(x) ? x.toLowerCase() : x;
|
|
87
82
|
};
|
|
88
83
|
}
|
|
89
84
|
return acc;
|
|
90
85
|
};
|
|
91
|
-
const transformFilter = ({ field, ignoreCase, value, operator }, preprocessors = {})
|
|
92
|
-
field = !isPresent(field) ? a
|
|
86
|
+
const transformFilter = ({ field, ignoreCase, value, operator }, preprocessors = {})=>{
|
|
87
|
+
field = !isPresent(field) ? (a)=>a : field;
|
|
93
88
|
ignoreCase = isPresent(ignoreCase) ? ignoreCase : true;
|
|
94
|
-
const itemProp = typedGetter(isFunction(field) ? field : a
|
|
89
|
+
const itemProp = typedGetter(isFunction(field) ? field : (a)=>{
|
|
95
90
|
const value = getter(field, true)(a);
|
|
96
91
|
const preprocessor = preprocessors[field];
|
|
97
92
|
return preprocessor ? preprocessor(value) : value;
|
|
98
93
|
}, value, ignoreCase);
|
|
99
94
|
value = convertValue(value, ignoreCase);
|
|
100
95
|
const op = isFunction(operator) ? operator : operatorsMap[operator];
|
|
101
|
-
return a
|
|
96
|
+
return (a)=>op(itemProp(a), value, ignoreCase);
|
|
102
97
|
};
|
|
103
98
|
/**
|
|
104
99
|
* @hidden
|
|
105
|
-
*/
|
|
106
|
-
export const transformCompositeFilter = (filter, preprocessors = {}) => {
|
|
100
|
+
*/ export const transformCompositeFilter = (filter, preprocessors = {})=>{
|
|
107
101
|
const combiner = logic[filter.logic];
|
|
108
|
-
return filter.filters
|
|
109
|
-
.filter(isPresent)
|
|
110
|
-
.map(x => isCompositeFilterDescriptor(x) ? transformCompositeFilter(x, preprocessors) : transformFilter(x, preprocessors))
|
|
111
|
-
.reduce(combiner.concat, combiner.identity);
|
|
102
|
+
return filter.filters.filter(isPresent).map((x)=>isCompositeFilterDescriptor(x) ? transformCompositeFilter(x, preprocessors) : transformFilter(x, preprocessors)).reduce(combiner.concat, combiner.identity);
|
|
112
103
|
};
|
|
104
|
+
|
|
113
105
|
//# sourceMappingURL=filter-no-eval.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/filtering/filter-no-eval.ts"],"sourcesContent":["import { CompositeFilterDescriptor, FilterDescriptor, isCompositeFilterDescriptor } from \"./filter-descriptor.interface\";\nimport { Predicate, Preprocessors } from \"../common.interfaces\";\nimport { getter } from \"../accessor\";\nimport { isFunction, isPresent, isDate, isString, isBlank, isNumeric, isArray } from \"../utils\";\n\nconst logic = {\n \"or\": {\n concat: (acc, fn) => a => acc(a) || fn(a),\n identity: () => false\n },\n \"and\": {\n concat: (acc, fn) => a => acc(a) && fn(a),\n identity: () => true\n }\n};\n\nconst operatorsMap = {\n contains: (a, b) => (a || \"\").indexOf(b) >= 0,\n doesnotcontain: (a, b) => (a || \"\").indexOf(b) === -1,\n doesnotendwith: (a, b) => (a || \"\").indexOf(b, (a || \"\").length - (b || \"\").length) < 0,\n doesnotstartwith: (a: string, b: string): boolean => (a || \"\").lastIndexOf(b, 0) === -1,\n endswith: (a: string, b: string): boolean => (a || \"\").indexOf(b, (a || \"\").length - (b || \"\").length) >= 0,\n eq: (a, b) => a === b,\n gt: <T>(a: T, b: T): boolean => a > b,\n gte: <T>(a: T, b: T): boolean => a >= b,\n isempty: (a: any) => isBlank(a) || a === '',\n isnotempty: (a: any) => isPresent(a) && a !== '',\n isnotnull: (a: any) => isPresent(a),\n isnull: (a: any) => isBlank(a),\n lt: <T>(a: T, b: T): boolean => a < b,\n lte: <T>(a: T, b: T): boolean => a <= b,\n neq: <T>(a: T, b: T): boolean => a != b, // tslint:disable-line:triple-equals\n startswith: (a: string, b: string): boolean => (a || \"\").lastIndexOf(b, 0) === 0,\n in: <T>(a: T, b: T[]): boolean => b.includes(a),\n notin: <T>(a: T, b: T[]): boolean => !b.includes(a),\n isinteger: (a: any) => isNumeric(a) && Math.round(a) === a,\n isfractional: (a: any) => isNumeric(a) && Math.round(a) !== a\n};\n\nconst dateRegExp = /^\\/Date\\((.*?)\\)\\/$/;\n\nconst convertValue = (value, ignoreCase) => {\n if (value != null && isString(value)) {\n const date = dateRegExp.exec(value);\n if (date) {\n return new Date(+date[1]).getTime();\n } else if (ignoreCase) {\n return value.toLowerCase();\n }\n } else if (value != null && isDate(value)) {\n return value.getTime();\n } else if (value != null && isArray(value)) {\n return value.map(v => isString(v) ? v.toLowerCase() : v);\n }\n return value;\n};\n\n\nconst typedGetter = (prop, value, ignoreCase) => {\n if (!isPresent(value)) {\n return prop;\n }\n\n let acc = prop;\n\n if (isString(value)) {\n const date = dateRegExp.exec(value);\n if (date) {\n value = new Date(+date[1]);\n } else {\n acc = a => {\n const x = prop(a);\n if (typeof x === 'string' && ignoreCase) {\n return x.toLowerCase();\n } else {\n return isNumeric(x) ? x + \"\" : x;\n }\n };\n }\n }\n\n if (isDate(value)) {\n return a => {\n const x = acc(a);\n return isDate(x) ? x.getTime() : x;\n };\n }\n\n if(isArray(value) && ignoreCase){\n acc = a => {\n const x = prop(a);\n return isString(x) ? x.toLowerCase() : x;\n };\n }\n\n return acc;\n};\n\nconst transformFilter = <T>({ field, ignoreCase, value, operator }: FilterDescriptor, preprocessors: Preprocessors<T> = {}): Predicate => {\n field = !isPresent(field) ? a => a : field;\n\n ignoreCase = isPresent(ignoreCase) ? ignoreCase : true;\n\n const itemProp = typedGetter(\n isFunction(field) ? field : a => {\n const value = getter(<string>field, true)(a);\n const preprocessor = preprocessors[<string>field];\n return preprocessor ? preprocessor(value) : value;\n },\n value,\n ignoreCase\n );\n\n value = convertValue(value, ignoreCase);\n\n const op = isFunction(operator) ? operator : operatorsMap[<string>operator];\n\n return a => op(itemProp(a), value, ignoreCase);\n};\n\n/**\n * @hidden\n */\nexport const transformCompositeFilter = <T>(filter: CompositeFilterDescriptor, preprocessors: Preprocessors<T> = {}): Predicate => {\n const combiner = logic[filter.logic];\n return filter.filters\n .filter(isPresent)\n .map(x => isCompositeFilterDescriptor(x) ? transformCompositeFilter(x, preprocessors) : transformFilter(x, preprocessors))\n .reduce(combiner.concat, combiner.identity);\n};\n"],"names":["isCompositeFilterDescriptor","getter","isFunction","isPresent","isDate","isString","isBlank","isNumeric","isArray","logic","concat","acc","fn","a","identity","operatorsMap","contains","b","indexOf","doesnotcontain","doesnotendwith","length","doesnotstartwith","lastIndexOf","endswith","eq","gt","gte","isempty","isnotempty","isnotnull","isnull","lt","lte","neq","startswith","in","includes","notin","isinteger","Math","round","isfractional","dateRegExp","convertValue","value","ignoreCase","date","exec","Date","getTime","toLowerCase","map","v","typedGetter","prop","x","transformFilter","field","operator","preprocessors","itemProp","preprocessor","op","transformCompositeFilter","filter","combiner","filters","reduce"],"mappings":"AAAA,SAAsDA,2BAA2B,QAAQ,gCAAgC;AAEzH,SAASC,MAAM,QAAQ,cAAc;AACrC,SAASC,UAAU,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,EAAEC,OAAO,EAAEC,SAAS,EAAEC,OAAO,QAAQ,WAAW;AAEhG,MAAMC,QAAQ;IACV,MAAM;QACFC,QAAQ,CAACC,KAAKC,KAAOC,CAAAA,IAAKF,IAAIE,MAAMD,GAAGC;QACvCC,UAAU,IAAM;IACpB;IACA,OAAO;QACHJ,QAAQ,CAACC,KAAKC,KAAOC,CAAAA,IAAKF,IAAIE,MAAMD,GAAGC;QACvCC,UAAU,IAAM;IACpB;AACJ;AAEA,MAAMC,eAAe;IACjBC,UAAU,CAACH,GAAGI,IAAM,AAACJ,CAAAA,KAAK,EAAC,EAAGK,OAAO,CAACD,MAAM;IAC5CE,gBAAgB,CAACN,GAAGI,IAAM,AAACJ,CAAAA,KAAK,EAAC,EAAGK,OAAO,CAACD,OAAO,CAAC;IACpDG,gBAAgB,CAACP,GAAGI,IAAM,AAACJ,CAAAA,KAAK,EAAC,EAAGK,OAAO,CAACD,GAAG,AAACJ,CAAAA,KAAK,EAAC,EAAGQ,MAAM,GAAG,AAACJ,CAAAA,KAAK,EAAC,EAAGI,MAAM,IAAI;IACtFC,kBAAkB,CAACT,GAAWI,IAAuB,AAACJ,CAAAA,KAAK,EAAC,EAAGU,WAAW,CAACN,GAAG,OAAO,CAAC;IACtFO,UAAU,CAACX,GAAWI,IAAuB,AAACJ,CAAAA,KAAK,EAAC,EAAGK,OAAO,CAACD,GAAG,AAACJ,CAAAA,KAAK,EAAC,EAAGQ,MAAM,GAAG,AAACJ,CAAAA,KAAK,EAAC,EAAGI,MAAM,KAAK;IAC1GI,IAAI,CAACZ,G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,aAAajB,SAASA;IAChD,GACAA,OACAC;IAGJD,QAAQD,aAAaC,OAAOC;IAE5B,MAAMiB,KAAK7D,WAAWyD,YAAYA,WAAW5C,YAAY,CAAS4C,SAAS;IAE3E,OAAO9C,CAAAA,IAAKkD,GAAGF,SAAShD,IAAIgC,OAAOC;AACvC;AAEA;;CAEC,GACD,OAAO,MAAMkB,2BAA2B,CAAIC,QAAmCL,gBAAkC,CAAC,CAAC;IAC/G,MAAMM,WAAWzD,KAAK,CAACwD,OAAOxD,KAAK,CAAC;IACpC,OAAOwD,OAAOE,OAAO,CAChBF,MAAM,CAAC9D,WACPiD,GAAG,CAACI,CAAAA,IAAKxD,4BAA4BwD,KAAKQ,yBAAyBR,GAAGI,iBAAiBH,gBAAgBD,GAAGI,gBAC1GQ,MAAM,CAACF,SAASxD,MAAM,EAAEwD,SAASpD,QAAQ;AAClD,EAAE"}
|
|
@@ -1,41 +1,41 @@
|
|
|
1
1
|
import { isPresent, isString, isArray } from '../utils';
|
|
2
2
|
import { isCompositeFilterDescriptor } from './filter-descriptor.interface';
|
|
3
|
-
const operatorMap = (key)
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}[key.toLowerCase()] || key
|
|
36
|
-
const normalizeOperator = (descriptor)
|
|
3
|
+
const operatorMap = (key)=>({
|
|
4
|
+
"!=": "neq",
|
|
5
|
+
"<": "lt",
|
|
6
|
+
"<=": "lte",
|
|
7
|
+
"==": "eq",
|
|
8
|
+
">": "gt",
|
|
9
|
+
">=": "gte",
|
|
10
|
+
equal: "eq",
|
|
11
|
+
equals: "eq",
|
|
12
|
+
equalto: "eq",
|
|
13
|
+
ge: "gte",
|
|
14
|
+
greater: "gt",
|
|
15
|
+
greaterthan: "gt",
|
|
16
|
+
greaterthanequal: "gte",
|
|
17
|
+
isempty: "isempty",
|
|
18
|
+
isequalto: "eq",
|
|
19
|
+
isgreaterthan: "gt",
|
|
20
|
+
isgreaterthanorequalto: "gte",
|
|
21
|
+
islessthan: "lt",
|
|
22
|
+
islessthanorequalto: "lte",
|
|
23
|
+
isnotempty: "isnotempty",
|
|
24
|
+
isnotequalto: "neq",
|
|
25
|
+
isnull: "isnull",
|
|
26
|
+
le: "lte",
|
|
27
|
+
less: "lt",
|
|
28
|
+
lessthan: "lt",
|
|
29
|
+
lessthanequal: "lte",
|
|
30
|
+
ne: "neq",
|
|
31
|
+
notequal: "neq",
|
|
32
|
+
notequals: "neq",
|
|
33
|
+
notequalto: "neq",
|
|
34
|
+
notsubstringof: "doesnotcontain"
|
|
35
|
+
})[key.toLowerCase()] || key;
|
|
36
|
+
const normalizeOperator = (descriptor)=>{
|
|
37
37
|
if (descriptor.filters) {
|
|
38
|
-
descriptor.filters = descriptor.filters.map(filter
|
|
38
|
+
descriptor.filters = descriptor.filters.map((filter)=>{
|
|
39
39
|
const result = Object.assign({}, filter);
|
|
40
40
|
if (!isCompositeFilterDescriptor(filter) && isString(filter.operator)) {
|
|
41
41
|
result.operator = operatorMap(filter.operator);
|
|
@@ -47,10 +47,12 @@ const normalizeOperator = (descriptor) => {
|
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
49
|
};
|
|
50
|
-
const normalizeDescriptor = (descriptor)
|
|
50
|
+
const normalizeDescriptor = (descriptor)=>{
|
|
51
51
|
if (!isCompositeFilterDescriptor(descriptor)) {
|
|
52
52
|
return {
|
|
53
|
-
filters: isArray(descriptor) ? descriptor : [
|
|
53
|
+
filters: isArray(descriptor) ? descriptor : [
|
|
54
|
+
descriptor
|
|
55
|
+
],
|
|
54
56
|
logic: "and"
|
|
55
57
|
};
|
|
56
58
|
}
|
|
@@ -62,13 +64,13 @@ const normalizeDescriptor = (descriptor) => {
|
|
|
62
64
|
*
|
|
63
65
|
* @param {CompositeFilterDescriptor | FilterDescriptor} descriptor - The descriptor that will be normalized.
|
|
64
66
|
* @returns {CompositeFilterDescriptor} - The normalized descriptor.
|
|
65
|
-
*/
|
|
66
|
-
|
|
67
|
-
export const normalizeFilters = (descriptor) => {
|
|
67
|
+
*/ // tslint:enable:max-line-length
|
|
68
|
+
export const normalizeFilters = (descriptor)=>{
|
|
68
69
|
if (isPresent(descriptor)) {
|
|
69
70
|
descriptor = normalizeDescriptor(descriptor);
|
|
70
71
|
normalizeOperator(descriptor);
|
|
71
72
|
}
|
|
72
73
|
return descriptor;
|
|
73
74
|
};
|
|
75
|
+
|
|
74
76
|
//# sourceMappingURL=filter.operators.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../../src/filtering/filter.operators.ts"],"sourcesContent":["import { isPresent, isString, isArray } from '../utils';\nimport { CompositeFilterDescriptor, FilterDescriptor, isCompositeFilterDescriptor } from './filter-descriptor.interface';\n\nconst operatorMap = (key) => ({\n \"!=\": \"neq\",\n \"<\": \"lt\",\n \"<=\": \"lte\",\n \"==\": \"eq\",\n \">\": \"gt\",\n \">=\": \"gte\",\n equal: \"eq\",\n equals: \"eq\",\n equalto: \"eq\",\n ge: \"gte\",\n greater: \"gt\",\n greaterthan: \"gt\",\n greaterthanequal: \"gte\",\n isempty: \"isempty\",\n isequalto: \"eq\",\n isgreaterthan: \"gt\",\n isgreaterthanorequalto: \"gte\",\n islessthan: \"lt\",\n islessthanorequalto: \"lte\",\n isnotempty: \"isnotempty\",\n isnotequalto: \"neq\",\n isnull: \"isnull\",\n le: \"lte\",\n less: \"lt\",\n lessthan: \"lt\",\n lessthanequal: \"lte\",\n ne: \"neq\",\n notequal: \"neq\",\n notequals: \"neq\",\n notequalto: \"neq\",\n notsubstringof: \"doesnotcontain\"\n}[key.toLowerCase()] || key);\n\nconst normalizeOperator = (descriptor: CompositeFilterDescriptor) => {\n if (descriptor.filters) {\n descriptor.filters = descriptor.filters.map(filter => {\n const result: any = Object.assign({}, filter);\n if (!isCompositeFilterDescriptor(filter) && isString(filter.operator)) {\n result.operator = operatorMap(filter.operator);\n }\n if (isCompositeFilterDescriptor(filter)) {\n normalizeOperator(result);\n }\n\n return result;\n });\n }\n};\n\nconst normalizeDescriptor = (descriptor): CompositeFilterDescriptor => {\n if (!isCompositeFilterDescriptor(descriptor)) {\n return {\n filters: isArray(descriptor) ? descriptor : [descriptor],\n logic: \"and\"\n };\n }\n return Object.assign({}, descriptor);\n};\n\n// tslint:disable:max-line-length\n/**\n * Converts a [`FilterDescriptor`]({% slug api_kendo-data-query_filterdescriptor %}) into a [`CompositeFilterDescriptor`]({% slug api_kendo-data-query_compositefilterdescriptor %}). If a `CompositeFilterDescriptor` is passed, no modifications will be made.\n *\n * @param {CompositeFilterDescriptor | FilterDescriptor} descriptor - The descriptor that will be normalized.\n * @returns {CompositeFilterDescriptor} - The normalized descriptor.\n */\n// tslint:enable:max-line-length\nexport const normalizeFilters = (descriptor: CompositeFilterDescriptor | FilterDescriptor): CompositeFilterDescriptor => {\n if (isPresent(descriptor)) {\n descriptor = normalizeDescriptor(descriptor);\n normalizeOperator(<CompositeFilterDescriptor>descriptor);\n }\n return <CompositeFilterDescriptor>descriptor;\n};\n"],"names":["isPresent","isString","isArray","isCompositeFilterDescriptor","operatorMap","key","equal","equals","equalto","ge","greater","greaterthan","greaterthanequal","isempty","isequalto","isgreaterthan","isgreaterthanorequalto","islessthan","islessthanorequalto","isnotempty","isnotequalto","isnull","le","less","lessthan","lessthanequal","ne","notequal","notequals","notequalto","notsubstringof","toLowerCase","normalizeOperator","descriptor","filters","map","filter","result","Object","assign","operator","normalizeDescriptor","logic","norm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AAChC,OAAO,MAAMU,mBAAmB,CAACV;IAC7B,IAAIjC,UAAUiC,aAAa;QACvBA,aAAaQ,oBAAoBR;QACjCD,kBAA6CC;IACjD;IACA,OAAkCA;AACtC,EAAE"}
|
package/dist/funcs.js
CHANGED
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @hidden
|
|
3
|
-
*/
|
|
4
|
-
export const ifElse = (predicate, right, left) => value => predicate(value) ? right(value) : left(value);
|
|
3
|
+
*/ export const ifElse = (predicate, right, left)=>(value)=>predicate(value) ? right(value) : left(value);
|
|
5
4
|
/**
|
|
6
5
|
* @hidden
|
|
7
6
|
* Performs the right-to-left function composition. Functions should have a unary.
|
|
8
|
-
*/
|
|
9
|
-
export const compose = (...args) => (data) => args.reduceRight((acc, curr) => curr(acc), data);
|
|
7
|
+
*/ export const compose = (...args)=>(data)=>args.reduceRight((acc, curr)=>curr(acc), data);
|
|
10
8
|
/**
|
|
11
9
|
* @hidden
|
|
12
|
-
*/
|
|
13
|
-
export const constant = x => () => x;
|
|
10
|
+
*/ export const constant = (x)=>()=>x;
|
|
14
11
|
/**
|
|
15
12
|
* @hidden
|
|
16
|
-
*/
|
|
17
|
-
|
|
13
|
+
*/ export const identity = (x)=>x;
|
|
14
|
+
|
|
18
15
|
//# sourceMappingURL=funcs.js.map
|
package/dist/funcs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"sources":["../src/funcs.ts"],"sourcesContent":["/**\n * @hidden\n */\nexport const ifElse = (predicate, right, left) => value => predicate(value) ? right(value) : left(value);\n\n/**\n * @hidden\n * Performs the right-to-left function composition. Functions should have a unary.\n */\nexport const compose = (...args) => (data) => args.reduceRight((acc, curr) => curr(acc), data);\n\n/**\n * @hidden\n */\nexport const constant = x => () => x;\n\n/**\n * @hidden\n */\nexport const identity = x => x;\n"],"names":["ifElse","predicate","right","left","value","compose","args","data","reduceRight","acc","curr","constant","x","identity"],"mappings":"AAAA;;CAEC,GACD,OAAO,MAAMA,SAAS,CAACC,WAAWC,OAAOC,OAASC,CAAAA,QAASH,UAAUG,SAASF,MAAME,SAASD,KAAKC,OAAO;AAEzG;;;CAGC,GACD,OAAO,MAAMC,UAAU,CAAC,GAAGC,OAAS,CAACC,OAASD,KAAKE,WAAW,CAAC,CAACC,KAAKC,OAASA,KAAKD,MAAMF,MAAM;AAE/F;;CAEC,GACD,OAAO,MAAMI,WAAWC,CAAAA,IAAK,IAAMA,EAAE;AAErC;;CAEC,GACD,OAAO,MAAMC,WAAWD,CAAAA,IAAKA,EAAE"}
|