From 4a12a2d3d75103bcc302275b1719b7778d4d1b87 Mon Sep 17 00:00:00 2001 From: ikusteu Date: Sun, 10 Sep 2023 11:34:40 +0200 Subject: [PATCH] Some copy/paste related fixes: * In firestore compat `doc` function, client variant: if doc path is not provided (we wish a new server-assigned id), pass only the parent node (to prevent empty path crashes) * In firestore compat `batch` function, bind `this` to returned `commit` methods (for both client and server variant) --- packages/client/src/utils/firestore/compat.ts | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/client/src/utils/firestore/compat.ts b/packages/client/src/utils/firestore/compat.ts index f77c9fe1b..235fc5ef3 100644 --- a/packages/client/src/utils/firestore/compat.ts +++ b/packages/client/src/utils/firestore/compat.ts @@ -94,12 +94,14 @@ export const doc = ( return match(node, { [FirestoreEnv.Client]: ({ instance }) => FirestoreDocVariant.client({ - // Even though 'doc' (aliased as 'clientDoc' here) works on both firestore and collection instanceerences, + // Even though 'doc' (aliased as 'clientDoc' here) works on both firestore and collection references, // it doesn't work well on unions because of slightly different type overloads, hence the typecast. - instance: clientDoc( - instance as ClientFirestore, - pathSegments.join("/") - ), + instance: docPath.length + ? clientDoc( + instance as ClientCollectionReference, + docPath.length ? docPath : undefined + ) + : clientDoc(instance as ClientCollectionReference), }), [FirestoreEnv.Server]: ({ instance }) => FirestoreDocVariant.server({ @@ -235,7 +237,7 @@ export const writeBatch = (db: FirestoreVariant) => } return batch.set(doc.instance, data); }, - commit: batch.commit, + commit: batch.commit.bind(batch), }; }, [FirestoreEnv.Server]: ({ instance }) => { @@ -248,7 +250,7 @@ export const writeBatch = (db: FirestoreVariant) => } return batch.set(doc.instance, data); }, - commit: batch.commit, + commit: batch.commit.bind(batch), }; }, });