Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | 21x 16x 15x 237x 236x 21x | /**
* Shared Firestore helper functions.
*
* Extracted from users.js, reports.js, banners.js, config.js, etc. to
* eliminate duplication.
*
* Spread-order invariant (`getDoc` and `queryDocs`): the payload is spread
* BEFORE the trusted `id` so a legacy or adversarially-shaped `id` field on
* the doc body cannot override the storage-layer key. See the "spread-order
* safety" tests in firestore-helpers.test.js for the failing-without-the-fix
* proof.
*/
const { db } = require('./firebase');
async function getDoc(path) {
const snap = await db.doc(path).get();
return snap.exists ? { ...snap.data(), id: snap.id } : null;
}
async function queryDocs(ref) {
const snap = await ref.get();
return snap.docs.map((d) => ({ ...d.data(), id: d.id }));
}
module.exports = { getDoc, queryDocs };
|