Skip to content

Commit

Permalink
add warning if not all records are returned
Browse files Browse the repository at this point in the history
  • Loading branch information
eluce2 committed Oct 8, 2024
1 parent fc8a791 commit 066f567
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @proofgeist/fmdapi

## 4.1.2

### Patch Changes

- Added console warning when not using pagination params and not all data is returned

## 4.1.1

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@proofgeist/fmdapi",
"version": "4.1.1",
"version": "4.1.2",
"description": "FileMaker Data API client",
"main": "dist/index.js",
"repository": "[email protected]:proofgeist/fm-dapi.git",
Expand Down
20 changes: 20 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ function DataApi<
timeout,
});

if (result.dataInfo.foundCount > result.dataInfo.returnedCount) {
// more records found than returned
if (args?.limit === undefined && args?.offset === undefined) {
// and the user didn't specify a limit or offset, so we should warn them
console.warn(
`🚨 @proofgeist/fmdapi: Loaded only ${result.dataInfo.returnedCount} of the ${result.dataInfo.foundCount} records from your "${layout}" layout. Use the "listAll" method to automatically paginate through all records, or specify a "limit" and "offset" to handle pagination yourself.`,
);
}
}

if (zodTypes) ZGetResponse(zodTypes).parse(result);
return result as GetResponse<T, U>;
}
Expand Down Expand Up @@ -306,6 +316,16 @@ function DataApi<
return { data: [] };
throw e;
})) as GetResponse<T, U>;

if (data.dataInfo.foundCount > data.dataInfo.returnedCount) {
// more records found than returned
if (args?.limit === undefined && args?.offset === undefined) {
console.warn(
`🚨 @proofgeistfmdapi: Loaded only ${data.dataInfo.returnedCount} of the ${data.dataInfo.foundCount} records from your "${layout}" layout. Use the "findAll" method to automatically paginate through all records, or specify a "limit" and "offset" to handle pagination yourself.`,
);
}
}

if (zodTypes && ignoreEmptyResult && data.data.length !== 0) {
// only parse this if we have data. Ignoring empty result won't match this anyway
ZGetResponse(zodTypes).parse(data);
Expand Down

0 comments on commit 066f567

Please sign in to comment.