Skip to content

Commit 318625b

Browse files
the0remlaurenzlong
authored andcommitted
Added support for Timestamp and DocumentReference (#28)
1 parent 8a623e9 commit 318625b

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/providers/firestore.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,21 @@ export function objectToValueProto(data: object) {
161161
bytesValue: val,
162162
};
163163
}
164+
if (val instanceof firestore.DocumentReference) {
165+
const projectId: string = get(val, '_referencePath.projectId');
166+
const database: string = get(val, '_referencePath.databaseId');
167+
const referenceValue: string = [
168+
'projects', projectId,
169+
'databases', database,
170+
val.path,
171+
].join('/');
172+
return { referenceValue };
173+
}
174+
if (val instanceof firestore.Timestamp) {
175+
return {
176+
timestampValue: val.toDate().toISOString(),
177+
};
178+
}
164179
if (isPlainObject(val)) {
165180
return {
166181
mapValue: {
@@ -170,7 +185,7 @@ export function objectToValueProto(data: object) {
170185
}
171186
throw new Error(
172187
'Cannot encode ' + val + 'to a Firestore Value.' +
173-
' Local testing does not yet support Firestore document reference values or geo points.');
188+
' Local testing does not yet support Firestore geo points.');
174189
};
175190

176191
return mapValues(data, encodeHelper);

0 commit comments

Comments
 (0)