The update method of BaseFirestoreRepository in Fireorm is not handling Timestamp objects created with the latest firebase-admin SDK v11.11.1. The Timestamp objects from firebase-admin v11.11.1 are not recognized as valid Firestore documents, whereas Timestamp objects from @google-cloud/firestore still work as expected.
Steps to Reproduce
Create an entity with a timestamp field.
Use firebase-admin SDK v11.11.1 to update the entity's timestamp field.
Attempt to update the entity in Firestore using Fireorm.
Observe the error related to the Timestamp object.
Expected Behavior
Fireorm should be able to handle Timestamp objects from the latest firebase-admin SDK without errors.
Actual Behavior
An error occurs, indicating that the Timestamp object is not a valid Firestore document.
Acceptance Criteria
Ensure compatibility with Timestamp objects from firebase-admin SDK v11.11.1.
Ensure backward compatibility with previous versions of firebase-admin and @google-cloud/firestore.
Add unit tests to validate the handling of Timestamp objects from different SDKs.
Additional Context
December 9, 2023: Initial issue raised about compatibility problems with firebase-admin SDK v11.11.1.
April 12, 2023: Similar issues reported with different projects using firebase-admin and @google-cloud/firestore.
Proposed API Changes
Update Timestamp Handling:
Modify the update method to handle Timestamp objects from both firebase-admin and @google-cloud/firestore.
import { firestore } from 'firebase-admin';
import { Timestamp as GCTimestamp } from '@google-cloud/firestore';
class BaseFirestoreRepository<T> {
async update(item: T): Promise<T> {
const plainObject = this.convertToPlainObject(item);
await this.firestoreColRef.doc(item.id).update(plainObject);
return item;
}
private convertToPlainObject(item: T): any {
const obj = JSON.parse(JSON.stringify(item));
for (const key in obj) {
if (obj[key] instanceof firestore.Timestamp || obj[key] instanceof GCTimestamp) {
obj[key] = obj[key].toDate();
}
}
return obj;
}
}
Unit Tests:
Add unit tests to validate the handling of Timestamp objects from different SDKs.
GorvGoyl's Issue (May 25, 2021): Describes a serialization error when trying to update an entity with a map of custom objects.
sc-cmendoza's Issue (Mar 2, 2021): Describes a similar issue where custom objects (e.g., GeoP) cause serialization errors in Firestore.
iKK001's Issue (Dec 9, 2023): Describes a compatibility issue with Timestamp objects in the latest firebase-admin SDK, which is another type of serialization problem.
Description
The
update
method ofBaseFirestoreRepository
in Fireorm is not handlingTimestamp
objects created with the latestfirebase-admin
SDK v11.11.1. TheTimestamp
objects fromfirebase-admin
v11.11.1 are not recognized as valid Firestore documents, whereasTimestamp
objects from@google-cloud/firestore
still work as expected.Steps to Reproduce
firebase-admin
SDK v11.11.1 to update the entity's timestamp field.Timestamp
object.Expected Behavior
Fireorm should be able to handle
Timestamp
objects from the latestfirebase-admin
SDK without errors.Actual Behavior
An error occurs, indicating that the
Timestamp
object is not a valid Firestore document.Acceptance Criteria
Timestamp
objects fromfirebase-admin
SDK v11.11.1.firebase-admin
and@google-cloud/firestore
.Timestamp
objects from different SDKs.Additional Context
firebase-admin
SDK v11.11.1.firebase-admin
and@google-cloud/firestore
.Proposed API Changes
Update Timestamp Handling:
update
method to handleTimestamp
objects from bothfirebase-admin
and@google-cloud/firestore
.Unit Tests:
Timestamp
objects from different SDKs.Example Implementation
Original Issue