-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b64a0c8
commit 82da1b9
Showing
5 changed files
with
83 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@flatfile/util-common': patch | ||
--- | ||
|
||
Added a utility to process all records |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './async.batch' | ||
export * from './logging.helper' | ||
export * from './process.records' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import api, { Flatfile } from '@flatfile/api' | ||
|
||
export async function processRecords<R>( | ||
sheetId: string, | ||
callback: (records: Flatfile.RecordsWithLinks) => R, | ||
recordGetOptions?: Omit<Flatfile.records.GetRecordsRequest, 'pageNumber'> | ||
): Promise<R[]> { | ||
let pageNumber = 1 | ||
const results: R[] = [] | ||
|
||
while (true) { | ||
const { | ||
data: { records }, | ||
} = await api.records.get(sheetId, { | ||
...recordGetOptions, | ||
pageNumber: pageNumber++, | ||
}) | ||
|
||
if (records.length === 0) { | ||
break | ||
} | ||
|
||
const result = callback(records) | ||
results.push(result) | ||
} | ||
|
||
return results | ||
} |