• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

odata2ts / odata2ts / 18874660384

28 Oct 2025 12:24PM UTC coverage: 93.773% (+0.007%) from 93.766%
18874660384

push

github

web-flow
feat(qobjects): allow arrays for in-filter (#363)

1541 of 1693 branches covered (91.02%)

Branch coverage included in aggregate %.

9 of 11 new or added lines in 1 file covered. (81.82%)

2811 of 2948 relevant lines covered (95.35%)

124.63 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.29
/packages/odata-query-objects/src/path/base/BaseFunctions.ts
1
import { StandardFilterOperators } from "../../odata/ODataModel";
2
import { buildQFilterOperation } from "../../param/UrlParamHelper";
3
import { QFilterExpression } from "../../QFilterExpression";
4
import { QOrderByExpression } from "../../QOrderByExpression";
5

6
export type MapValue<T> = (value: T) => string;
7

8
export function orderAscending(path: string) {
9
  /**
10
   * Order by this property in ascending order.
11
   *
12
   * @returns orderby expression
13
   */
14
  return () => new QOrderByExpression(`${path} asc`);
883✔
15
}
16

17
export function orderDescending(path: string) {
18
  /**
19
   * Order by this property in descending order.
20
   *
21
   * @returns orderby expression
22
   */
23
  return () => new QOrderByExpression(`${path} desc`);
883✔
24
}
25

26
export function filterIsNull(path: string) {
27
  /**
28
   * Base filter function: property must be null.
29
   */
30
  return () => new QFilterExpression(`${path} eq null`);
883✔
31
}
32

33
export function filterIsNotNull(path: string) {
34
  /**
35
   * Base filter function: property must not be null.
36
   */
37
  return () => new QFilterExpression(`${path} ne null`);
883✔
38
}
39

40
export function filterEquals<T>(path: string, mapValue: MapValue<T>) {
41
  /**
42
   * Base filter function: property must equal the given value.
43
   */
44
  return (value: T | null) => {
883✔
45
    const result = value === null ? "null" : mapValue(value);
260✔
46
    return buildQFilterOperation(path, StandardFilterOperators.EQUALS, result);
259✔
47
  };
48
}
49

50
export function filterNotEquals<T>(path: string, mapValue: MapValue<T>) {
51
  /**
52
   * Base filter function: property must not equal the given value.
53
   */
54
  return (value: T | null) => {
883✔
55
    const result = value === null ? "null" : mapValue(value);
56✔
56
    return buildQFilterOperation(path, StandardFilterOperators.NOT_EQUALS, result);
56✔
57
  };
58
}
59

60
export function filterLowerThan<T>(path: string, mapValue: MapValue<T>) {
61
  /**
62
   * Base filter function: property must be lower than the given value.
63
   */
64
  return (value: T) => {
883✔
65
    return buildQFilterOperation(path, StandardFilterOperators.LOWER_THAN, mapValue(value));
44✔
66
  };
67
}
68

69
export function filterLowerEquals<T>(path: string, mapValue: MapValue<T>) {
70
  /**
71
   * Base filter function: property must be lower than or equal to the given value.
72
   */
73
  return (value: T) => {
883✔
74
    return buildQFilterOperation(path, StandardFilterOperators.LOWER_EQUALS, mapValue(value));
44✔
75
  };
76
}
77

78
export function filterGreaterThan<T>(path: string, mapValue: MapValue<T>) {
79
  /**
80
   * Base filter function: property must be greater than the given value.
81
   */
82
  return (value: T) => {
883✔
83
    return buildQFilterOperation(path, StandardFilterOperators.GREATER_THAN, mapValue(value));
67✔
84
  };
85
}
86

87
export function filterGreaterEquals<T>(path: string, mapValue: MapValue<T>) {
88
  /**
89
   * Base filter function: property must be greater than or equal to the given value.
90
   */
91
  return (value: T) => {
883✔
92
    return buildQFilterOperation(path, StandardFilterOperators.GREATER_EQUALS, mapValue(value));
44✔
93
  };
94
}
95

96
export function filterInEmulated<T>(path: string, mapValue: MapValue<T>) {
97
  /**
98
   * Base filter function: property must equal one of the given values.
99
   *
100
   * The in-statement is actually emulated by using an or-concatenation of equals-statements.
101
   */
102
  return (...values: Array<T | Array<T>>) => {
883✔
103
    return flattenList(values).reduce<QFilterExpression>((expression, value, idx, coll) => {
46✔
104
      const expr = buildQFilterOperation(path, StandardFilterOperators.EQUALS, mapValue(value));
80✔
105
      return expression.or(expr, idx < coll.length - 1);
80✔
106
    }, new QFilterExpression());
107
  };
108
}
109

110
export function filterIn<T>(path: string, mapValue: MapValue<T>) {
111
  /**
112
   * Base filter function (V4): property must equal one of the given values.
113
   *
114
   * This implementation uses the native in-statement which is available since V4, but not implemented by
115
   * all V4 OData services.
116
   */
NEW
117
  return (...values: Array<T | Array<T>>) => {
×
NEW
118
    return buildQFilterOperation(path, StandardFilterOperators.IN, `(${flattenList(values).map(mapValue).join(",")})`);
×
119
  };
120
}
121

122
function flattenList<T>(values: Array<T | Array<T>>): Array<T> {
123
  return values.reduce<Array<T>>((collector, current) => {
46✔
124
    if (Array.isArray(current)) {
70✔
125
      collector.push(...current);
10✔
126
    } else {
127
      collector.push(current);
60✔
128
    }
129
    return collector;
70✔
130
  }, []);
131
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc