UNPKG

@sap-cloud-sdk/odata-v4

Version:

SAP Cloud SDK for JavaScript common functions of OData client generator and OpenAPI clint generator.

35 lines 1.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.filterFunction = filterFunction; const internal_1 = require("@sap-cloud-sdk/odata-common/internal"); const filter_1 = require("./filter"); /** * Build a custom filter function. * @param functionName - The name of the function, e.g., `substring`. * @param returnType - The return type of the filter function. * @param parameters - The parameter(s) used in the function. * @returns An instance of filter function suited for the given return type. */ function filterFunction(functionName, returnType, ...parameters) { if (returnType === 'datetimeoffset') { return new filter_1.DateFilterFunction(functionName, parameters); } if (isCollectionReturnType(returnType)) { const edmType = returnTypeMapping[returnType.replace('[]', '')]; if (edmType) { return new internal_1.CollectionFilterFunction(functionName, parameters, edmType); } throw new Error(`Cannot create filter function for unknown return type ${returnType}.`); } return (0, internal_1.createFilterFunction)(functionName, returnType, ...parameters); } function isCollectionReturnType(returnType) { return returnType.endsWith('[]'); } const returnTypeMapping = { datetimeoffset: 'Edm.DateTimeOffset', boolean: 'Edm.Boolean', string: 'Edm.String', ...internal_1.numberReturnTypeMapping }; //# sourceMappingURL=filter-function.js.map