Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/get-documents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import {
getDocs,
limit,
query,
type CollectionReference,
type DocumentData,
type QueryConstraint,
} from "firebase/firestore";
import { makeMutableDocument } from "./make-mutable-document";

export async function getDocuments<T extends DocumentData>(
collectionRef: CollectionReference<T>,
...queryConstraints: QueryConstraint[]
) {
const _query =
queryConstraints.length === 0
? query(collectionRef, limit(500))
: query(collectionRef, ...queryConstraints);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicated query-building logic in same file

Low Severity

The query-building block (checking queryConstraints.length, applying limit(500) default, or spreading user constraints) is duplicated verbatim between getDocuments and getDocumentsData in the same file. If the default behavior ever changes (e.g., adjusting the default limit), both copies need to be updated in sync, risking divergence. A small shared helper within this file would eliminate that risk.

Additional Locations (1)

Fix in Cursor Fix in Web


const snapshot = await getDocs(_query);

return snapshot.docs.map((doc) => makeMutableDocument(doc));
}

export async function getDocumentsData<T extends DocumentData>(
collectionRef: CollectionReference<T>,
...queryConstraints: QueryConstraint[]
) {
const _query =
queryConstraints.length === 0
? query(collectionRef, limit(500))
: query(collectionRef, ...queryConstraints);

const snapshot = await getDocs(_query);

return snapshot.docs.map((doc) => doc.data());
}
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./get-document";
export * from "./get-documents";
export * from "./get-specific-document";
export * from "./make-document";
export * from "./make-mutable-document";
Expand Down