@@ -390,10 +390,35 @@ export class Query {
390
390
}
391
391
}
392
392
393
- export interface Filter {
394
- matches ( doc : Document ) : boolean ;
395
- canonicalId ( ) : string ;
396
- isEqual ( filter : Filter ) : boolean ;
393
+ export abstract class Filter {
394
+ abstract matches ( doc : Document ) : boolean ;
395
+ abstract canonicalId ( ) : string ;
396
+ abstract isEqual ( filter : Filter ) : boolean ;
397
+
398
+ /**
399
+ * Creates a filter based on the provided arguments.
400
+ */
401
+ static create ( field : FieldPath , op : RelationOp , value : FieldValue ) : Filter {
402
+ if ( value . isEqual ( NullValue . INSTANCE ) ) {
403
+ if ( op !== RelationOp . EQUAL ) {
404
+ throw new FirestoreError (
405
+ Code . INVALID_ARGUMENT ,
406
+ 'Invalid query. You can only perform equals comparisons on null.'
407
+ ) ;
408
+ }
409
+ return new NullFilter ( field ) ;
410
+ } else if ( value . isEqual ( DoubleValue . NAN ) ) {
411
+ if ( op !== RelationOp . EQUAL ) {
412
+ throw new FirestoreError (
413
+ Code . INVALID_ARGUMENT ,
414
+ 'Invalid query. You can only perform equals comparisons on NaN.'
415
+ ) ;
416
+ }
417
+ return new NanFilter ( field ) ;
418
+ } else {
419
+ return new RelationFilter ( field , op , value ) ;
420
+ }
421
+ }
397
422
}
398
423
399
424
export class RelationOp {
@@ -434,12 +459,14 @@ export class RelationOp {
434
459
}
435
460
}
436
461
437
- export class RelationFilter implements Filter {
462
+ export class RelationFilter extends Filter {
438
463
constructor (
439
464
public field : FieldPath ,
440
465
public op : RelationOp ,
441
466
public value : FieldValue
442
- ) { }
467
+ ) {
468
+ super ( ) ;
469
+ }
443
470
444
471
matches ( doc : Document ) : boolean {
445
472
if ( this . field . isKeyField ( ) ) {
@@ -528,8 +555,10 @@ export class RelationFilter implements Filter {
528
555
/**
529
556
* Filter that matches 'null' values.
530
557
*/
531
- export class NullFilter implements Filter {
532
- constructor ( public field : FieldPath ) { }
558
+ export class NullFilter extends Filter {
559
+ constructor ( public field : FieldPath ) {
560
+ super ( ) ;
561
+ }
533
562
534
563
matches ( doc : Document ) : boolean {
535
564
const val = doc . field ( this . field ) ;
@@ -556,8 +585,10 @@ export class NullFilter implements Filter {
556
585
/**
557
586
* Filter that matches 'NaN' values.
558
587
*/
559
- export class NanFilter implements Filter {
560
- constructor ( public field : FieldPath ) { }
588
+ export class NanFilter extends Filter {
589
+ constructor ( public field : FieldPath ) {
590
+ super ( ) ;
591
+ }
561
592
562
593
matches ( doc : Document ) : boolean {
563
594
const val = doc . field ( this . field ) . value ( ) ;
@@ -581,35 +612,6 @@ export class NanFilter implements Filter {
581
612
}
582
613
}
583
614
584
- /**
585
- * Creates a filter based on the provided arguments.
586
- */
587
- export function fieldFilter (
588
- field : FieldPath ,
589
- op : RelationOp ,
590
- value : FieldValue
591
- ) : Filter {
592
- if ( value . isEqual ( NullValue . INSTANCE ) ) {
593
- if ( op !== RelationOp . EQUAL ) {
594
- throw new FirestoreError (
595
- Code . INVALID_ARGUMENT ,
596
- 'Invalid query. You can only perform equals ' + 'comparisons on null.'
597
- ) ;
598
- }
599
- return new NullFilter ( field ) ;
600
- } else if ( value . isEqual ( DoubleValue . NAN ) ) {
601
- if ( op !== RelationOp . EQUAL ) {
602
- throw new FirestoreError (
603
- Code . INVALID_ARGUMENT ,
604
- 'Invalid query. You can only perform equals ' + 'comparisons on NaN.'
605
- ) ;
606
- }
607
- return new NanFilter ( field ) ;
608
- } else {
609
- return new RelationFilter ( field , op , value ) ;
610
- }
611
- }
612
-
613
615
/**
614
616
* The direction of sorting in an order by.
615
617
*/
0 commit comments