Skip to content

Commit b403624

Browse files
Adding MaybeDocument
1 parent 4625e84 commit b403624

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

packages/firestore/src/model/document.ts

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,20 @@ export interface DocumentOptions {
2626
hasLocalMutations: boolean;
2727
}
2828

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+
readonly key: DocumentKey;
35+
readonly version: SnapshotVersion;
36+
}
37+
38+
/**
39+
* Represents a document in Firestore with a key, version, data and whether the
40+
* data has localmutations applied to it.
41+
*/
42+
export class Document implements MaybeDocument {
3043
readonly hasLocalMutations: boolean;
3144

3245
constructor(
@@ -68,7 +81,7 @@ export class Document {
6881
);
6982
}
7083

71-
static compareByKey(d1: MaybeDocument, d2: MaybeDocument): number {
84+
static compareByKey(d1: Document, d2: Document): number {
7285
return DocumentKey.comparator(d1.key, d2.key);
7386
}
7487

@@ -88,7 +101,7 @@ export class Document {
88101
* Version is set to 0 if we don't point to any specific time, otherwise it
89102
* denotes time we know it didn't exist at.
90103
*/
91-
export class NoDocument {
104+
export class NoDocument implements MaybeDocument {
92105
constructor(readonly key: DocumentKey, readonly version: SnapshotVersion) {}
93106

94107
toString(): string {
@@ -102,14 +115,4 @@ export class NoDocument {
102115
other.key.isEqual(this.key)
103116
);
104117
}
105-
106-
static compareByKey(d1: MaybeDocument, d2: MaybeDocument): number {
107-
return DocumentKey.comparator(d1.key, d2.key);
108-
}
109118
}
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

Comments
 (0)