-
Notifications
You must be signed in to change notification settings - Fork 79
Description
The update method of BaseFirestoreRepository
of fireorm
cannot deal with a date that is created with neest 'firebase-admin' SDK v11.11.1 anymore. (i.e. update(item: T): Promise<T>;
)
import { Timestamp } from 'firebase-admin'; // DOES NOT WORK !!!!!!
import { Timestamp } from '@google-cloud/firestore'; // WORKS !!!!!!!
async updateApi(
trucId: String,
): Promise<Truc | undefined> {
const truc: Truc = await this.findTruc(trucID);
let updateTruc = truc;
updateTruc.changedAt = Timestamp.fromDate(new Date());
// filter out fields with undefined values from the updateTruc
for (const key in updateTruc) {
if (updateTruc[key] === undefined) {
delete updateTruc[key];
}
}
// Update the Firestore document with the updateTruc fields
await this.update({ ...truc, ...updateTruc });
return updateTruc;
}
Before, with firebase-admin
SDK version 11.9.0, everything worked:
"dependencies": {
"firebase-admin": "^11.9.0"
},
This works with v11.9.0:
import { firestore } from 'firebase-admin';
updateTruc.changedAt = firestore.Timestamp.fromDate(new Date());
But now, with firebase-admin
SDK version 11.11.1, the collection-udpate crashes:
"dependencies": {
"firebase-admin": "^11.11.1"
},
import { Timestamp } from 'firebase-admin';
updateTruc.changedAt = Timestamp.fromDate(new Date());
The error message is:
Update() requires either a single JavaScript object or an alternating list of field/value pairs that can be followed by an optional precondition. Value for argument "dataOrField" is not a valid Firestore document. Detected an object of type "Timestamp" that doesn't match the expected instance.
After some more investigation:
The way it still works is as follows !!!!!!
"dependencies": {
"@google-cloud/firestore": "^7.1.0",
},
import { Timestamp } from '@google-cloud/firestore';
updateTruc.changedAt = Timestamp.fromDate(new Date());
Summary:
@google-cloud/firestore 7.1.0 WORKS (calling updateTruc.changedAt = Timestamp.fromDate(new Date());
)
firebase-admin 11.9.0 WORKS (calling updateTruc.changedAt = firestore.Timestamp.fromDate(new Date());
)
firebase-admin 11.11.1 DOES NOT WORK !!!!!! (calling updateTruc.changedAt = Timestamp.fromDate(new Date());
)
It seems that fireorm
can only handle Timestamps from @google-cloud/firestore - but no longer with newest version of firebase-admin v11.11.1. (It was able to do it with firebase-admin v10.9.0 - but no longer with v11.11.1 anymore).
So clearly, the firebase-admin SDK added an incompatibility for dates with respect to fireorm updates.
Can fireorm
please be fully compatible again to newest fierebase-admin
SDK ??
Or what 's the problem suddenly with firebase-admin
v11.11.1 ??