( schema: TItemSchema, url: string, params: FetchCursorPageParams, requestInit?: RequestInit, options?: ZodFetchOptions )
| 44 | } |
| 45 | |
| 46 | export function zodfetchCursorPage<TItemSchema extends z.ZodTypeAny>( |
| 47 | schema: TItemSchema, |
| 48 | url: string, |
| 49 | params: FetchCursorPageParams, |
| 50 | requestInit?: RequestInit, |
| 51 | options?: ZodFetchOptions |
| 52 | ) { |
| 53 | const query = new URLSearchParams(params.query); |
| 54 | |
| 55 | if (params.limit) { |
| 56 | query.set("page[size]", String(params.limit)); |
| 57 | } |
| 58 | |
| 59 | if (params.after) { |
| 60 | query.set("page[after]", params.after); |
| 61 | } |
| 62 | |
| 63 | if (params.before) { |
| 64 | query.set("page[before]", params.before); |
| 65 | } |
| 66 | |
| 67 | const cursorPageSchema = z.object({ |
| 68 | data: z.array(schema), |
| 69 | pagination: z.object({ |
| 70 | next: z.string().optional(), |
| 71 | previous: z.string().optional(), |
| 72 | }), |
| 73 | }); |
| 74 | |
| 75 | const $url = new URL(url); |
| 76 | $url.search = query.toString(); |
| 77 | |
| 78 | const fetchResult = _doZodFetch(cursorPageSchema, $url.href, requestInit, options); |
| 79 | |
| 80 | return new CursorPagePromise(fetchResult, schema, url, params, requestInit, options); |
| 81 | } |
| 82 | |
| 83 | export function zodfetchOffsetLimitPage<TItemSchema extends z.ZodTypeAny>( |
| 84 | schema: TItemSchema, |
no test coverage detected
searching dependent graphs…