Skip to content

Commit

Permalink
feat:process-records-utility (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
carlbrugger authored Oct 19, 2023
1 parent b64a0c8 commit 82da1b9
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/angry-ears-boil.md
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
49 changes: 45 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion utils/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,8 @@
"url": "https://github.com/FlatFilers/flatfile-plugins.git",
"directory": "utils/common"
},
"license": "ISC"
"license": "ISC",
"dependencies": {
"@flatfile/api": "^1.5.32"
}
}
1 change: 1 addition & 0 deletions utils/common/src/index.ts
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'
28 changes: 28 additions & 0 deletions utils/common/src/process.records.ts
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
}

0 comments on commit 82da1b9

Please sign in to comment.