| 1 | import { z } from 'zod' |
| 2 | import { ChannelPaginationMode } from './platforms.interface' |
| 3 | |
| 4 | export const ChannelPaginationMetadataVoSchema = z.discriminatedUnion('mode', [ |
| 5 | z.object({ |
| 6 | mode: z.literal(ChannelPaginationMode.Cursor).describe('分页模式'), |
| 7 | defaultLimit: z.number().int().positive().describe('默认数量'), |
| 8 | maxLimit: z.number().int().positive().describe('最大数量'), |
| 9 | supportsPrevious: z.boolean().describe('是否支持上一页'), |
| 10 | }), |
| 11 | z.object({ |
| 12 | mode: z.literal(ChannelPaginationMode.Page).describe('分页模式'), |
| 13 | defaultPageSize: z.number().int().positive().describe('默认每页数量'), |
| 14 | maxPageSize: z.number().int().positive().describe('最大每页数量'), |
| 15 | supportsTotal: z.boolean().describe('是否返回总数'), |
| 16 | }), |
| 17 | z.object({ |
| 18 | mode: z.literal(ChannelPaginationMode.None).describe('分页模式'), |
| 19 | }), |
| 20 | ]).describe('分页能力元数据') |
| 21 | |
| 22 | export const ChannelPaginationResultVoSchema = z.discriminatedUnion('mode', [ |
| 23 | z.object({ |
| 24 | mode: z.literal(ChannelPaginationMode.Cursor).describe('分页模式'), |
| 25 | nextCursor: z.string().optional().describe('下一页游标'), |
| 26 | previousCursor: z.string().optional().describe('上一页游标'), |
| 27 | hasNext: z.boolean().describe('是否有下一页'), |
| 28 | hasPrevious: z.boolean().describe('是否有上一页'), |
| 29 | limit: z.number().int().positive().describe('每页数量'), |
| 30 | }), |
| 31 | z.object({ |
| 32 | mode: z.literal(ChannelPaginationMode.Page).describe('分页模式'), |
| 33 | page: z.number().int().positive().describe('页码'), |
| 34 | pageSize: z.number().int().positive().describe('每页数量'), |
| 35 | total: z.number().int().nonnegative().optional().describe('总数'), |
| 36 | hasNext: z.boolean().describe('是否有下一页'), |
| 37 | hasPrevious: z.boolean().describe('是否有上一页'), |
| 38 | }), |
| 39 | z.object({ |
| 40 | mode: z.literal(ChannelPaginationMode.None).describe('分页模式'), |
| 41 | }), |
| 42 | ]) |
| 43 |