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:
@@ -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() }));
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user