UNPKG

2.65 kBJavaScriptView Raw
1"use strict";
2var __assign = (this && this.__assign) || function () {
3 __assign = Object.assign || function(t) {
4 for (var s, i = 1, n = arguments.length; i < n; i++) {
5 s = arguments[i];
6 for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7 t[p] = s[p];
8 }
9 return t;
10 };
11 return __assign.apply(this, arguments);
12};
13var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14 if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15 if (ar || !(i in from)) {
16 if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17 ar[i] = from[i];
18 }
19 }
20 return to.concat(ar || Array.prototype.slice.call(from));
21};
22Object.defineProperty(exports, "__esModule", { value: true });
23exports.filterFunctionV4 = exports.filterFunction = void 0;
24var filter_function_1 = require("../odata-common/filter/filter-function");
25var collection_filter_function_1 = require("../odata-common/filter/collection-filter-function");
26var date_filter_function_1 = require("./filter/date-filter-function");
27/**
28 * Build a custom filter function.
29 * @param functionName - the name of the function, e.g., `substring`
30 * @param returnType - the return type of the filter function
31 * @param parameters - the parameter(s) used in the function
32 * @returns An instance of filter function suited for the given return type
33 */
34function filterFunction(functionName, returnType) {
35 var parameters = [];
36 for (var _i = 2; _i < arguments.length; _i++) {
37 parameters[_i - 2] = arguments[_i];
38 }
39 if (returnType === 'datetimeoffset') {
40 return new date_filter_function_1.DateFilterFunction(functionName, parameters);
41 }
42 if (isCollectionReturnType(returnType)) {
43 var edmType = returnTypeMapping[returnType.replace('[]', '')];
44 if (edmType) {
45 return new collection_filter_function_1.CollectionFilterFunction(functionName, parameters, edmType);
46 }
47 throw new Error("Cannot create filter function for unknown return type ".concat(returnType, "."));
48 }
49 return filter_function_1.createFilterFunction.apply(void 0, __spreadArray([functionName, returnType], parameters, false));
50}
51exports.filterFunction = filterFunction;
52exports.filterFunctionV4 = filterFunction;
53function isCollectionReturnType(returnType) {
54 return returnType.endsWith('[]');
55}
56var returnTypeMapping = __assign({ datetimeoffset: 'Edm.DateTimeOffset', boolean: 'Edm.Boolean', string: 'Edm.String' }, filter_function_1.numberReturnTypeMapping);
57//# sourceMappingURL=filter-function.js.map
\No newline at end of file