1
- export interface Condition < T = unknown > {
2
- readonly operator : string ;
3
- readonly value : T ;
1
+ export interface Note < T > {
2
+ type : string
3
+ message ?: string
4
+ originalValue ?: T
4
5
}
5
6
6
- export class DocumentCondition < T > implements Condition < T > {
7
- public readonly operator ! : string ;
7
+ export abstract class Condition < T = unknown > {
8
+ private _notes ?: Note < T > [ ] ;
8
9
9
- public readonly value ! : T ;
10
+ constructor (
11
+ public readonly operator : string ,
12
+ public readonly value : T
13
+ ) { }
10
14
11
- constructor ( operator : string , value : T ) {
12
- this . operator = operator ;
13
- this . value = value ;
15
+ get notes ( ) : ReadonlyArray < Note < T > > | undefined {
16
+ return this . _notes ;
17
+ }
18
+
19
+ addNote ( note : Note < T > ) {
20
+ this . _notes = this . _notes || [ ] ;
21
+ this . _notes . push ( note ) ;
14
22
}
15
23
}
16
24
17
- export class CompoundCondition < T extends Condition = Condition > extends DocumentCondition < T [ ] > {
18
- public readonly operator ! : string ;
25
+ export class DocumentCondition < T > extends Condition < T > {
26
+ }
19
27
28
+ export class CompoundCondition < T extends Condition = Condition > extends DocumentCondition < T [ ] > {
20
29
constructor ( operator : string , conditions : T [ ] ) {
21
30
if ( ! Array . isArray ( conditions ) ) {
22
31
throw new Error ( `"${ operator } " operator expects to receive an array of conditions` ) ;
@@ -27,16 +36,11 @@ export class CompoundCondition<T extends Condition = Condition> extends Document
27
36
}
28
37
29
38
export const ITSELF = '__itself__' ;
30
- export class FieldCondition < T = unknown > implements Condition < T > {
31
- public readonly operator ! : string ;
32
-
39
+ export class FieldCondition < T = unknown > extends Condition < T > {
33
40
public readonly field ! : string | typeof ITSELF ;
34
41
35
- public readonly value ! : T ;
36
-
37
42
constructor ( operator : string , field : string | typeof ITSELF , value : T ) {
38
- this . operator = operator ;
39
- this . value = value ;
43
+ super ( operator , value ) ;
40
44
this . field = field ;
41
45
}
42
46
}
0 commit comments