M2: refactor all firebase write sites to storage adapter

- 37 call sites: setDoc/updateDoc/deleteDoc/addDoc/getDocs/writeBatch -> storage.*
- adapter wraps SDK, path-string interface
- storage instance app-wide (getStorage)
- firebase.js: static imports (getDoc/getDocs alias), no dynamic import

56 frontend tests green. STORAGE=firebase = identical behavior.
This commit is contained in:
david raistrick
2026-06-28 21:05:39 -04:00
parent 5bb9e5fc19
commit 812298fa73
2 changed files with 57 additions and 54 deletions
+4 -4
View File
@@ -11,8 +11,8 @@
import { initializeApp } from 'firebase/app';
import { getAuth, signInAnonymously, onAuthStateChanged, signInWithCustomToken } from 'firebase/auth';
import {
getFirestore, doc, setDoc, updateDoc, deleteDoc, addDoc, collection,
onSnapshot, query, orderBy, limit, writeBatch, serverTimestamp,
getFirestore, doc, setDoc, getDoc as getDocReal, getDocs as getDocsReal, addDoc, collection,
onSnapshot, updateDoc, deleteDoc, query, orderBy, limit, writeBatch, serverTimestamp,
} from 'firebase/firestore';
// Path helpers mirror App.js getPath object.
@@ -74,7 +74,7 @@ export function createFirebaseStorage() {
return {
async getDoc(path) {
const snap = await import('firebase/firestore').then(({ getDoc: gd, doc: d }) => gd(d(db, path)));
const snap = await getDocReal(doc(db, path));
return snap.exists() ? { id: snap.id, ...snap.data() } : null;
},
@@ -96,7 +96,7 @@ export function createFirebaseStorage() {
},
async getCollection(collectionPath) {
const snapshot = await import('firebase/firestore').then(({ getDocs: gd, collection: c }) => gd(c(db, collectionPath)));
const snapshot = await getDocsReal(collection(db, collectionPath));
return snapshot.docs.map(d => ({ id: d.id, ...d.data() }));
},