@@ -26,15 +26,32 @@ export interface DocumentOptions {
26
26
hasLocalMutations : boolean ;
27
27
}
28
28
29
- export class Document {
29
+ /**
30
+ * The result of a lookup for a given path may be an existing document or a
31
+ * marker that this document does not exist at a given version.
32
+ */
33
+ export abstract class MaybeDocument {
34
+ constructor ( readonly key : DocumentKey , readonly version : SnapshotVersion ) { }
35
+
36
+ static compareByKey ( d1 : MaybeDocument , d2 : MaybeDocument ) : number {
37
+ return DocumentKey . comparator ( d1 . key , d2 . key ) ;
38
+ }
39
+ }
40
+
41
+ /**
42
+ * Represents a document in Firestore with a key, version, data and whether the
43
+ * data has local mutations applied to it.
44
+ */
45
+ export class Document extends MaybeDocument {
30
46
readonly hasLocalMutations : boolean ;
31
47
32
48
constructor (
33
- readonly key : DocumentKey ,
34
- readonly version : SnapshotVersion ,
49
+ key : DocumentKey ,
50
+ version : SnapshotVersion ,
35
51
readonly data : ObjectValue ,
36
52
options : DocumentOptions
37
53
) {
54
+ super ( key , version ) ;
38
55
this . hasLocalMutations = options . hasLocalMutations ;
39
56
}
40
57
@@ -68,10 +85,6 @@ export class Document {
68
85
) ;
69
86
}
70
87
71
- static compareByKey ( d1 : MaybeDocument , d2 : MaybeDocument ) : number {
72
- return DocumentKey . comparator ( d1 . key , d2 . key ) ;
73
- }
74
-
75
88
static compareByField ( field : FieldPath , d1 : Document , d2 : Document ) : number {
76
89
const v1 = d1 . field ( field ) ;
77
90
const v2 = d2 . field ( field ) ;
@@ -88,8 +101,10 @@ export class Document {
88
101
* Version is set to 0 if we don't point to any specific time, otherwise it
89
102
* denotes time we know it didn't exist at.
90
103
*/
91
- export class NoDocument {
92
- constructor ( readonly key : DocumentKey , readonly version : SnapshotVersion ) { }
104
+ export class NoDocument extends MaybeDocument {
105
+ constructor ( key : DocumentKey , version : SnapshotVersion ) {
106
+ super ( key , version ) ;
107
+ }
93
108
94
109
toString ( ) : string {
95
110
return `NoDocument(${ this . key } , ${ this . version } )` ;
@@ -102,14 +117,4 @@ export class NoDocument {
102
117
other . key . isEqual ( this . key )
103
118
) ;
104
119
}
105
-
106
- static compareByKey ( d1 : MaybeDocument , d2 : MaybeDocument ) : number {
107
- return DocumentKey . comparator ( d1 . key , d2 . key ) ;
108
- }
109
120
}
110
-
111
- /**
112
- * A union type representing either a full document or a deleted document.
113
- * The NoDocument is used when it doesn't exist on the server.
114
- */
115
- export type MaybeDocument = Document | NoDocument ;
0 commit comments