-
Notifications
You must be signed in to change notification settings - Fork 1
feat: api-common supporting numeric cursors #832
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
CarlosGamero
wants to merge
10
commits into
main
from
feat/api_common_improving_encode_cursor_feature
Closed
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1080117
Adjusting createPaginatedResponse to support not string single cursor…
CarlosGamero 89e3e5b
Improving naming
CarlosGamero 324278e
Making has more mandatory
CarlosGamero 37f15c4
Removing deprecates
CarlosGamero 0552207
doc changes
CarlosGamero 5931c08
Improving handling of single cursor values
CarlosGamero 569d9d1
Chaning again approach for numbers -> we need to encode them
CarlosGamero 602ce1c
Updating encoded cursor schema to support new behaviour
CarlosGamero 8979bc9
zod deprecate
CarlosGamero 23c9889
Test fix
CarlosGamero File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -22,18 +22,19 @@ export type AfterPaginationParams = z.infer<typeof AFTER_PAGINATION_CONFIG_SCHEM | |
| const decodeCursorHook = (value: string | undefined, ctx: RefinementCtx) => { | ||
| if (!value) return undefined | ||
|
|
||
| // Try to decode as base64 (for encoded numbers/objects) | ||
| const result = decodeCursor(value) | ||
| if (result.result) return result.result | ||
|
|
||
| ctx.addIssue({ | ||
| message: 'Invalid cursor', | ||
| code: z.ZodIssueCode.custom, | ||
| params: { message: result.error.message }, | ||
| code: 'custom', | ||
| params: { message: result.error?.message }, | ||
|
Comment on lines
-30
to
+32
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. z.ZodIssueCode is deprecated |
||
| }) | ||
| } | ||
|
|
||
| export const multiCursorMandatoryPaginationSchema = < | ||
| CursorType extends z.ZodSchema<unknown, Record<string, unknown> | undefined>, | ||
| export const encodedCursorMandatoryPaginationSchema = < | ||
| CursorType extends z.ZodSchema<unknown, Record<string, unknown> | number | undefined>, | ||
| >( | ||
| cursorType: CursorType, | ||
| ) => { | ||
|
|
@@ -44,16 +45,16 @@ export const multiCursorMandatoryPaginationSchema = < | |
| after: cursor, | ||
| }) | ||
| } | ||
| export const multiCursorOptionalPaginationSchema = < | ||
| CursorType extends z.ZodSchema<unknown, Record<string, unknown> | undefined>, | ||
| export const encodedCursorOptionalPaginationSchema = < | ||
| CursorType extends z.ZodSchema<unknown, Record<string, unknown> | number | undefined>, | ||
| >( | ||
| cursorType: CursorType, | ||
| ) => multiCursorMandatoryPaginationSchema(cursorType).partial({ limit: true }) | ||
| ) => encodedCursorMandatoryPaginationSchema(cursorType).partial({ limit: true }) | ||
|
|
||
| export const zMeta = z.object({ | ||
| count: z.number(), | ||
| cursor: z.string().optional().describe('Pagination cursor, a last item id from this result set'), | ||
| hasMore: z.boolean().optional().describe('Whether there are more items to fetch'), | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Only a couple of endpoints are using meta without |
||
| hasMore: z.boolean().describe('Whether there are more items to fetch'), | ||
| }) | ||
|
|
||
| export type PaginationMeta = z.infer<typeof zMeta> | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No longer needed