Skip to content

Added support for Timestamp and DocumentReference #28

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/providers/firestore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,21 @@ export function objectToValueProto(data: object) {
bytesValue: val,
};
}
if (val instanceof firestore.DocumentReference) {
const projectId: string = get(val, '_referencePath.projectId');
const database: string = get(val, '_referencePath.databaseId');
const referenceValue: string = [
'projects', projectId,
'databases', database,
val.path,
].join('/');
return { referenceValue };
}
if (val instanceof firestore.Timestamp) {
return {
timestampValue: val.toDate().toISOString(),
};
}
if (isPlainObject(val)) {
return {
mapValue: {
Expand All @@ -170,7 +185,7 @@ export function objectToValueProto(data: object) {
}
throw new Error(
'Cannot encode ' + val + 'to a Firestore Value.' +
' Local testing does not yet support Firestore document reference values or geo points.');
' Local testing does not yet support Firestore geo points.');
};

return mapValues(data, encodeHelper);
Expand Down