UNPKG

5.57 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};
13Object.defineProperty(exports, "__esModule", { value: true });
14exports.filterFunctionsV4 = exports.filterFunctions = exports.hasSubsequence = exports.hasSubset = exports.now = exports.minDateTime = exports.maxDateTime = exports.totalOffsetMinutes = exports.fractionalSeconds = exports.matchesPattern = exports.contains = void 0;
15var filter_functions_1 = require("../odata-common/filter/filter-functions");
16var filter_function_1 = require("./filter-function");
17/* String Functions */
18/**
19 * Build a filter function to test whether a string is a substring of the other. Evaluates to boolean.
20 * @param substr - The substring to test for. This can either be a string, a reference to a field or another filter function.
21 * @param str - The string to test. This can either be a string, a reference to a field or another filter function.
22 *
23 * @returns The newly created filter function
24 */
25function contains(substr, str) {
26 return filter_function_1.filterFunction('contains', 'boolean', substr, str);
27}
28exports.contains = contains;
29/**
30 * Build a filter function to test whether a string matches a pattern. Evaluates to boolean.
31 * @param str - The string to get the index from. This can either be a string, a reference to a field or another filter function.
32 * @param regex - The pattern to test against. This should be a regular expression as a string.
33 * @returns The newly created filter function
34 */
35function matchesPattern(str, regex) {
36 return filter_function_1.filterFunction('matchesPattern', 'boolean', str, regex);
37}
38exports.matchesPattern = matchesPattern;
39/* Date Functions */
40/**
41 * Build a filter function to get the fractional seconds of a date. Evaluates to decimal.
42 * @param date - The date to get the fractional seconds for. This can either be a date (Moment) or a reference to a field.
43 * @returns The newly created filter function
44 */
45function fractionalSeconds(date) {
46 return filter_function_1.filterFunction('fractionalseconds', 'decimal', date);
47}
48exports.fractionalSeconds = fractionalSeconds;
49/**
50 * Build a filter function to get the signed number of minutes in the time zone offset. Evaluates to int.
51 * @param date - The date to get the offset minutes for. This can either be a date (Moment) or a reference to a field.
52 * @returns The newly created filter function
53 */
54function totalOffsetMinutes(date) {
55 return filter_function_1.filterFunction('totaloffsetminutes', 'decimal', date);
56}
57exports.totalOffsetMinutes = totalOffsetMinutes;
58/**
59 * Build a filter function to get the latest possible point in time. Evaluates to DateTimeOffset.
60 * @returns The newly created filter function
61 */
62function maxDateTime() {
63 return filter_function_1.filterFunction('maxdatetime', 'decimal');
64}
65exports.maxDateTime = maxDateTime;
66/**
67 * Build a filter function to get the earliest possible point in time. Evaluates to DateTimeOffset.
68 * @returns The newly created filter function
69 */
70function minDateTime() {
71 return filter_function_1.filterFunction('mindatetime', 'decimal');
72}
73exports.minDateTime = minDateTime;
74/**
75 * Build a filter function to get the current point in time. Evaluates to DateTimeOffset.
76 * @returns The newly created filter function
77 */
78function now() {
79 return filter_function_1.filterFunction('now', 'decimal');
80}
81exports.now = now;
82/* Collection functions */
83/**
84 * Build a filter function to test whether a set is a subset of the other, i. e. whether the second parameter can be transformed into the first by reordering and / or removing items. Evaluates to boolean.
85 * @param subset - The subset to test for. This can either be an array, a reference to a field or another filter function.
86 * @param set - The set to test. This can either be an array, a reference to a field or another filter function.
87 *
88 * @returns The newly created filter function
89 */
90function hasSubset(subset, set) {
91 return filter_function_1.filterFunction('hassubset', 'boolean', subset, set);
92}
93exports.hasSubset = hasSubset;
94/**
95 * Build a filter function to test whether a set is a subsequence of the other, i. e. whether the second parameter can be transformed into the first by removing items. Evaluates to boolean.
96 * @param subsequence - The subsequence to test for. This can either be an array, a reference to a field or another filter function.
97 * @param sequence - The sequence to test. This can either be an array, a reference to a field or another filter function.
98 *
99 * @returns The newly created filter function
100 */
101function hasSubsequence(subsequence, sequence) {
102 return filter_function_1.filterFunction('hassubsequence', 'boolean', subsequence, sequence);
103}
104exports.hasSubsequence = hasSubsequence;
105/**
106 * TODO: totalseconds, time
107 */
108/**
109 * OData v4 specific filter functions
110 */
111exports.filterFunctions = __assign(__assign({}, filter_functions_1.filterFunctions), { contains: contains, matchesPattern: matchesPattern, fractionalSeconds: fractionalSeconds, totalOffsetMinutes: totalOffsetMinutes, maxDateTime: maxDateTime, minDateTime: minDateTime, now: now, hasSubset: hasSubset, hasSubsequence: hasSubsequence });
112exports.filterFunctionsV4 = exports.filterFunctions;
113//# sourceMappingURL=filter-functions.js.map
\No newline at end of file