-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore!: limit TX pagination number for
getTransactionsSummaries
(#3400
- Loading branch information
1 parent
bdf0ebe
commit efdc721
Showing
5 changed files
with
132 additions
and
53 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 @@ | ||
--- | ||
"@fuel-ts/account": minor | ||
--- | ||
|
||
chore!: limit TX pagination number for `getTransactionsSummaries` |
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
49 changes: 49 additions & 0 deletions
49
packages/account/src/providers/utils/validate-pagination-args.ts
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,49 @@ | ||
import { FuelError, ErrorCode } from '@fuel-ts/errors'; | ||
|
||
import type { CursorPaginationArgs } from '../provider'; | ||
|
||
/** | ||
* @hidden | ||
*/ | ||
export const validatePaginationArgs = (params: { | ||
inputArgs?: CursorPaginationArgs; | ||
paginationLimit: number; | ||
}): CursorPaginationArgs => { | ||
const { paginationLimit, inputArgs = {} } = params; | ||
const { first, last, after, before } = inputArgs; | ||
|
||
if (after && before) { | ||
throw new FuelError( | ||
ErrorCode.INVALID_INPUT_PARAMETERS, | ||
'Pagination arguments "after" and "before" cannot be used together' | ||
); | ||
} | ||
|
||
if ((first || 0) > paginationLimit || (last || 0) > paginationLimit) { | ||
throw new FuelError( | ||
ErrorCode.INVALID_INPUT_PARAMETERS, | ||
`Pagination limit for this query cannot exceed ${paginationLimit} items` | ||
); | ||
} | ||
|
||
if (first && before) { | ||
throw new FuelError( | ||
ErrorCode.INVALID_INPUT_PARAMETERS, | ||
'The use of pagination argument "first" with "before" is not supported' | ||
); | ||
} | ||
|
||
if (last && after) { | ||
throw new FuelError( | ||
ErrorCode.INVALID_INPUT_PARAMETERS, | ||
'The use of pagination argument "last" with "after" is not supported' | ||
); | ||
} | ||
|
||
// If neither first nor last is provided, set a default first value | ||
if (!first && !last) { | ||
inputArgs.first = paginationLimit; | ||
} | ||
|
||
return inputArgs; | ||
}; |
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