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

typeorm / typeorm / 15219332477

23 May 2025 09:13PM UTC coverage: 17.216% (-59.1%) from 76.346%
15219332477

Pull #11332

github

naorpeled
cr comments - move if block
Pull Request #11332: feat: add new undefined and null behavior flags

1603 of 12759 branches covered (12.56%)

Branch coverage included in aggregate %.

0 of 31 new or added lines in 3 files covered. (0.0%)

14132 existing lines in 166 files now uncovered.

4731 of 24033 relevant lines covered (19.69%)

60.22 hits per line

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

6.25
/src/find-options/FindOperator.ts
1
import { ObjectLiteral } from "../common/ObjectLiteral"
2
import { FindOperatorType } from "./FindOperatorType"
3
import { InstanceChecker } from "../util/InstanceChecker"
1✔
4
import { ValueTransformer } from "../decorator/options/ValueTransformer"
5
import { ApplyValueTransformers } from "../util/ApplyValueTransformers"
1✔
6

7
type SqlGeneratorType = (aliasPath: string) => string
8

9
/**
10
 * Find Operator used in Find Conditions.
11
 */
12
export class FindOperator<T> {
1✔
UNCOV
13
    readonly "@instanceof" = Symbol.for("FindOperator")
×
14

15
    // -------------------------------------------------------------------------
16
    // Private Properties
17
    // -------------------------------------------------------------------------
18

19
    /**
20
     * Operator type.
21
     */
22
    private _type: FindOperatorType
23

24
    /**
25
     * Parameter value.
26
     */
27
    private _value: T | FindOperator<T>
28

29
    /**
30
     * ObjectLiteral parameters.
31
     */
32
    private _objectLiteralParameters: ObjectLiteral | undefined
33

34
    /**
35
     * Indicates if parameter is used or not for this operator.
36
     */
37
    private _useParameter: boolean
38

39
    /**
40
     * Indicates if multiple parameters must be used for this operator.
41
     */
42
    private _multipleParameters: boolean
43

44
    /**
45
     * SQL generator
46
     */
47
    private _getSql: SqlGeneratorType | undefined
48

49
    // -------------------------------------------------------------------------
50
    // Constructor
51
    // -------------------------------------------------------------------------
52

53
    constructor(
54
        type: FindOperatorType,
55
        value: T | FindOperator<T>,
56
        useParameter: boolean = true,
×
57
        multipleParameters: boolean = false,
×
58
        getSql?: SqlGeneratorType,
59
        objectLiteralParameters?: ObjectLiteral,
60
    ) {
UNCOV
61
        this._type = type
×
UNCOV
62
        this._value = value
×
UNCOV
63
        this._useParameter = useParameter
×
UNCOV
64
        this._multipleParameters = multipleParameters
×
UNCOV
65
        this._getSql = getSql
×
UNCOV
66
        this._objectLiteralParameters = objectLiteralParameters
×
67
    }
68

69
    // -------------------------------------------------------------------------
70
    // Accessors
71
    // -------------------------------------------------------------------------
72

73
    /**
74
     * Indicates if parameter is used or not for this operator.
75
     * Extracts final value if value is another find operator.
76
     */
77
    get useParameter(): boolean {
UNCOV
78
        if (InstanceChecker.isFindOperator(this._value))
×
UNCOV
79
            return this._value.useParameter
×
80

UNCOV
81
        return this._useParameter
×
82
    }
83

84
    /**
85
     * Indicates if multiple parameters must be used for this operator.
86
     * Extracts final value if value is another find operator.
87
     */
88
    get multipleParameters(): boolean {
UNCOV
89
        if (InstanceChecker.isFindOperator(this._value))
×
UNCOV
90
            return this._value.multipleParameters
×
91

UNCOV
92
        return this._multipleParameters
×
93
    }
94

95
    /**
96
     * Gets the Type of this FindOperator
97
     */
98
    get type(): FindOperatorType {
UNCOV
99
        return this._type
×
100
    }
101

102
    /**
103
     * Gets the final value needs to be used as parameter value.
104
     */
105
    get value(): T {
UNCOV
106
        if (InstanceChecker.isFindOperator(this._value))
×
UNCOV
107
            return this._value.value
×
108

UNCOV
109
        return this._value
×
110
    }
111

112
    /**
113
     * Gets ObjectLiteral parameters.
114
     */
115
    get objectLiteralParameters(): ObjectLiteral | undefined {
UNCOV
116
        if (InstanceChecker.isFindOperator(this._value))
×
UNCOV
117
            return this._value.objectLiteralParameters
×
118

UNCOV
119
        return this._objectLiteralParameters
×
120
    }
121

122
    /**
123
     * Gets the child FindOperator if it exists
124
     */
125
    get child(): FindOperator<T> | undefined {
UNCOV
126
        if (InstanceChecker.isFindOperator(this._value)) return this._value
×
127

UNCOV
128
        return undefined
×
129
    }
130

131
    /**
132
     * Gets the SQL generator
133
     */
134
    get getSql(): SqlGeneratorType | undefined {
UNCOV
135
        if (InstanceChecker.isFindOperator(this._value))
×
136
            return this._value.getSql
×
137

UNCOV
138
        return this._getSql
×
139
    }
140

141
    transformValue(transformer: ValueTransformer | ValueTransformer[]) {
UNCOV
142
        if (this._value instanceof FindOperator) {
×
UNCOV
143
            this._value.transformValue(transformer)
×
144
        } else {
UNCOV
145
            this._value =
×
146
                Array.isArray(this._value) && this._multipleParameters
×
147
                    ? this._value.map(
148
                          (v: any) =>
UNCOV
149
                              transformer &&
×
150
                              ApplyValueTransformers.transformTo(
151
                                  transformer,
152
                                  v,
153
                              ),
154
                      )
155
                    : ApplyValueTransformers.transformTo(
156
                          transformer,
157
                          this._value,
158
                      )
159
        }
160
    }
161
}
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

© 2025 Coveralls, Inc