Skip to content

Commit e217aea

Browse files
authored
feat: add option for listing raw docs (#431)
1 parent e12001c commit e217aea

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

.changeset/silent-eyes-drop.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@blinkk/root-cms': patch
3+
---
4+
5+
feat: add option for listing raw docs

packages/root-cms/core/client.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export interface ListDocsOptions {
105105
orderBy?: string;
106106
orderByDirection?: 'asc' | 'desc';
107107
query?: (query: Query) => Query;
108+
/**
109+
* Whether to fetch the "raw" version of the doc (for use in conjunction with
110+
* `setRawDoc()`).
111+
*/
112+
raw?: boolean;
108113
}
109114

110115
export interface GetCountOptions {
@@ -306,8 +311,15 @@ export class RootCMSClient {
306311
const results = await query.get();
307312
const docs: T[] = [];
308313
results.forEach((result) => {
309-
const doc = unmarshalData(result.data()) as T;
310-
docs.push(doc);
314+
if (options.raw) {
315+
// For callers that wish to modify the raw doc via `setRawDoc()`,
316+
// return the unmodified doc as returned from firestore.
317+
const rawDoc = result.data() as T;
318+
docs.push(rawDoc);
319+
} else {
320+
const doc = unmarshalData(result.data()) as T;
321+
docs.push(doc);
322+
}
311323
});
312324
return {docs};
313325
}

0 commit comments

Comments
 (0)