@longzai-intelligence/pagination 0.0.1 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. package/README.md +36 -203
  2. package/dist/hono.cjs +1 -0
  3. package/dist/hono.d.cts +15 -0
  4. package/dist/hono.d.mts +15 -0
  5. package/dist/hono.mjs +1 -0
  6. package/dist/index-C4IwIpFc.d.mts +199 -0
  7. package/dist/index-DpbbjAwO.d.cts +199 -0
  8. package/dist/index.cjs +1 -1
  9. package/dist/index.d.cts +79 -80
  10. package/dist/index.d.mts +79 -80
  11. package/dist/index.mjs +1 -1
  12. package/dist/typeorm.cjs +1 -0
  13. package/dist/typeorm.d.cts +26 -0
  14. package/dist/typeorm.d.mts +26 -0
  15. package/dist/typeorm.mjs +1 -0
  16. package/dist/utils-B200OLT-.cjs +1 -0
  17. package/dist/utils-DsM7-PZL.mjs +1 -0
  18. package/package.json +29 -5
  19. package/.turbo/turbo-build.log +0 -22
  20. package/.turbo/turbo-lint.log +0 -1
  21. package/.turbo/turbo-test$colon$coverage.log +0 -36
  22. package/.turbo/turbo-test.log +0 -14
  23. package/.turbo/turbo-typecheck.log +0 -4
  24. package/CHANGELOG.md +0 -11
  25. package/coverage/base.css +0 -224
  26. package/coverage/block-navigation.js +0 -87
  27. package/coverage/coverage-final.json +0 -12
  28. package/coverage/favicon.png +0 -0
  29. package/coverage/index.html +0 -161
  30. package/coverage/prettify.css +0 -1
  31. package/coverage/prettify.js +0 -2
  32. package/coverage/sort-arrow-sprite.png +0 -0
  33. package/coverage/sorter.js +0 -210
  34. package/coverage/src/adapters/index.html +0 -131
  35. package/coverage/src/adapters/index.ts.html +0 -118
  36. package/coverage/src/adapters/typeorm.adapter.ts.html +0 -940
  37. package/coverage/src/index.html +0 -116
  38. package/coverage/src/index.ts.html +0 -253
  39. package/coverage/src/types/index.html +0 -176
  40. package/coverage/src/types/index.ts.html +0 -133
  41. package/coverage/src/types/pagination.types.ts.html +0 -292
  42. package/coverage/src/types/result.types.ts.html +0 -415
  43. package/coverage/src/types/sort.types.ts.html +0 -265
  44. package/coverage/src/types/typeorm.d.ts.html +0 -196
  45. package/coverage/src/utils/index.html +0 -146
  46. package/coverage/src/utils/index.ts.html +0 -178
  47. package/coverage/src/utils/pagination.util.ts.html +0 -703
  48. package/coverage/src/utils/validation.util.ts.html +0 -535
  49. package/eslint.config.ts +0 -3
  50. package/src/__tests__/index.test.ts +0 -66
  51. package/src/__tests__/pagination.util.test.ts +0 -253
  52. package/src/__tests__/typeorm.adapter.test.ts +0 -214
  53. package/src/__tests__/validation.util.test.ts +0 -122
  54. package/src/adapters/index.ts +0 -11
  55. package/src/adapters/typeorm.adapter.ts +0 -285
  56. package/src/index.ts +0 -56
  57. package/src/types/index.ts +0 -16
  58. package/src/types/pagination.types.ts +0 -69
  59. package/src/types/result.types.ts +0 -110
  60. package/src/types/sort.types.ts +0 -60
  61. package/src/types/typeorm.d.ts +0 -37
  62. package/src/utils/index.ts +0 -31
  63. package/src/utils/pagination.util.ts +0 -206
  64. package/src/utils/validation.util.ts +0 -150
  65. package/tsconfig/.cache/app.tsbuildinfo +0 -1
  66. package/tsconfig/.cache/build.tsbuildinfo +0 -1
  67. package/tsconfig/.cache/node.tsbuildinfo +0 -1
  68. package/tsconfig/.cache/test.tsbuildinfo +0 -1
  69. package/tsconfig/app.json +0 -12
  70. package/tsconfig/node.json +0 -11
  71. package/tsconfig/test.json +0 -14
  72. package/tsconfig.json +0 -9
  73. package/tsdown.config.ts +0 -6
  74. package/vitest.config.ts +0 -3
package/README.md CHANGED
@@ -10,209 +10,42 @@ bun add @longzai-intelligence/pagination
10
10
 
11
11
  ## 特性
12
12
 
13
- - 类型安全的分页参数定义
14
- - 支持 page/pageSize 和 limit/offset 两种分页风格
15
- - 支持游标分页
16
- - 提供参数验证工具
17
- - 提供 TypeORM 适配器(可选)
18
-
19
- ## 快速开始
20
-
21
- ### 基本使用
22
-
23
- ```typescript
24
- import {
25
- normalizePagination,
26
- calculateOffset,
27
- createPaginatedResult,
28
- type PaginationParams,
29
- type PaginatedResult,
30
- } from '@longzai-intelligence/pagination';
31
-
32
- // 规范化分页参数
33
- const params: PaginationParams = { page: 2, pageSize: 20 };
34
- const { page, pageSize } = normalizePagination(params);
35
-
36
- // 计算偏移量
37
- const offset = calculateOffset(page, pageSize);
38
-
39
- // 创建分页结果
40
- const result: PaginatedResult<User> = createPaginatedResult(
41
- users,
42
- total,
43
- page,
44
- pageSize,
45
- );
46
- ```
47
-
48
- ### 参数验证
49
-
50
- ```typescript
51
- import {
52
- isValidPage,
53
- isValidPageSize,
54
- isValidPagination,
55
- } from '@longzai-intelligence/pagination';
56
-
57
- if (isValidPagination(params)) {
58
- // 参数有效
59
- }
60
-
61
- if (isValidPage(1) && isValidPageSize(20)) {
62
- // 页码和页面大小有效
63
- }
64
- ```
65
-
66
- ### TypeORM 适配器
67
-
68
- ```typescript
69
- import {
70
- paginateWithRepository,
71
- paginateWithQueryBuilder,
72
- } from '@longzai-intelligence/pagination';
73
-
74
- // 使用 Repository 分页
75
- const result = await paginateWithRepository(userRepository, {
76
- page: 1,
77
- pageSize: 20,
78
- }, {
79
- where: { active: true },
80
- order: { createdAt: 'DESC' },
81
- });
82
-
83
- // 使用 QueryBuilder 分页
84
- const qb = userRepository.createQueryBuilder('user');
85
- const result = await paginateWithQueryBuilder(qb, { page: 1, pageSize: 20 });
86
- ```
87
-
88
- ## API 文档
89
-
90
- ### 类型
91
-
92
- #### PaginationParams
93
-
94
- ```typescript
95
- interface PaginationParams {
96
- page?: number; // 页码,从 1 开始
97
- pageSize?: number; // 每页数量
98
- }
99
- ```
100
-
101
- #### OffsetPaginationParams
102
-
103
- ```typescript
104
- interface OffsetPaginationParams {
105
- limit?: number; // 每页数量
106
- offset?: number; // 偏移量
107
- }
108
- ```
109
-
110
- #### PaginatedResult
111
-
112
- ```typescript
113
- interface PaginatedResult<T> {
114
- items: T[]; // 数据项
115
- total: number; // 总记录数
116
- page: number; // 当前页码
117
- pageSize: number; // 每页数量
118
- totalPages: number; // 总页数
119
- hasNextPage: boolean; // 是否有下一页
120
- hasPreviousPage: boolean; // 是否有上一页
121
- }
122
- ```
123
-
124
- #### SortParams
125
-
126
- ```typescript
127
- interface SortParams<T extends string = string> {
128
- sortBy?: T; // 排序字段
129
- sortOrder?: 'asc' | 'desc'; // 排序方向
130
- }
131
- ```
132
-
133
- ### 常量
134
-
135
- #### PAGINATION_DEFAULTS
136
-
137
- ```typescript
138
- const PAGINATION_DEFAULTS = {
139
- page: 1,
140
- pageSize: 20,
141
- maxPageSize: 100,
142
- minPageSize: 1,
143
- } as const;
144
- ```
145
-
146
- ### 工具函数
147
-
148
- #### normalizePagination(params?)
149
-
150
- 规范化分页参数,确保参数在有效范围内。
151
-
152
- ```typescript
153
- const { page, pageSize } = normalizePagination({ page: 2, pageSize: 50 });
154
- ```
155
-
156
- #### calculateOffset(page, pageSize)
157
-
158
- 计算偏移量。
159
-
160
- ```typescript
161
- const offset = calculateOffset(2, 20); // 20
162
- ```
163
-
164
- #### calculateTotalPages(total, pageSize)
165
-
166
- 计算总页数。
167
-
168
- ```typescript
169
- const totalPages = calculateTotalPages(100, 20); // 5
170
- ```
171
-
172
- #### hasNextPage(page, totalPages) / hasPreviousPage(page)
173
-
174
- 判断是否有下一页/上一页。
175
-
176
- ```typescript
177
- hasNextPage(1, 5); // true
178
- hasPreviousPage(1); // false
179
- ```
180
-
181
- #### offsetToPage(offset, limit) / pageToOffset(page, pageSize)
182
-
183
- 分页风格转换。
184
-
185
- ```typescript
186
- offsetToPage(20, 20); // { page: 2, pageSize: 20 }
187
- pageToOffset(2, 20); // { offset: 20, limit: 20 }
188
- ```
189
-
190
- ### 验证函数
191
-
192
- #### isValidPage(page)
193
-
194
- 验证页码是否有效(正整数)。
195
-
196
- #### isValidPageSize(pageSize)
197
-
198
- 验证每页数量是否有效(1-100 之间的整数)。
199
-
200
- #### isValidOffset(offset)
201
-
202
- 验证偏移量是否有效(非负整数)。
203
-
204
- #### isValidLimit(limit)
205
-
206
- 验证限制数量是否有效(1-100 之间的整数)。
207
-
208
- #### isValidPagination(params)
209
-
210
- 验证分页参数对象是否有效。
211
-
212
- #### isValidOffsetPagination(params)
213
-
214
- 验证 offset 分页参数对象是否有效。
13
+ - 类型安全的分页参数定义(page/pageSize、limit/offset、cursor)
14
+ - Schema 工厂函数动态创建分页 Schema
15
+ - 预设函数提供场景化分页方案
16
+ - 参数验证工具
17
+ - TypeORM 适配器(可选)
18
+ - Hono 适配器(可选)
19
+
20
+ ## 导出概览
21
+
22
+ ### 主入口 `@longzai-intelligence/pagination`
23
+
24
+ | 分类 | 导出 |
25
+ |------|------|
26
+ | 参数类型 | `PaginationParams`、`OffsetPaginationParams`、`CursorPaginationParams` |
27
+ | 结果类型 | `PaginatedResult`、`OffsetPaginatedResult`、`CursorPaginatedResult`、`CompactPaginatedResult` |
28
+ | 排序类型 | `SortOrder`、`SortParams`、`MultiSortParams` |
29
+ | Schema 工厂 | `createPaginationSchema`、`createResultSchema` |
30
+ | 预设函数 | `createTablePreset`、`createInfiniteScrollPreset`、`createTimelinePreset`、`createCompactListPreset` |
31
+ | 工具函数 | `normalizePagination`、`calculateOffset`、`createPaginatedResult`、`createPaginationDefaults` |
32
+ | 验证函数 | `isValidPage`、`isValidPageSize`、`isValidPagination` 等 |
33
+
34
+ ### 子路径导出
35
+
36
+ | 路径 | 说明 |
37
+ |------|------|
38
+ | `@longzai-intelligence/pagination/typeorm` | TypeORM 适配器 |
39
+ | `@longzai-intelligence/pagination/hono` | Hono 适配器 |
40
+
41
+ ## 依赖要求
42
+
43
+ | 包 | 版本 | 说明 |
44
+ |------|------|------|
45
+ | typeorm | `^0.3.0` | 可选,使用 TypeORM 适配器时需要 |
46
+ | zod | `^4.0.0` | 可选,使用 Schema 功能时需要 |
47
+ | hono | `^4.0.0` | 可选,使用 Hono 适配器时需要 |
215
48
 
216
49
  ## 许可证
217
50
 
218
- MIT
51
+ UNLICENSED
package/dist/hono.cjs ADDED
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});let e=require(`zod`);function t(e){if(e===void 0)return;let t=Number(e);return Number.isNaN(t)?void 0:t}function n(n,r){let i=r.shape,a={};for(let[r]of Object.entries(i))if(n[r]!==void 0){let o=i[r];o instanceof e.z.ZodNumber||o instanceof e.z.ZodOptional&&o.unwrap()instanceof e.z.ZodNumber?a[r]=t(n[r]):a[r]=n[r]}return r.parse(a)}function r(e,t){let n=e.sortBy,r=e.sortOrder;if(n&&t&&!t.includes(n))return{};if(r&&r!==`asc`&&r!==`desc`)return{sortBy:n};let i={};return n&&(i.sortBy=n),r&&(i.sortOrder=r),i}exports.parsePaginationFromQuery=n,exports.parseSortFromQuery=r;
@@ -0,0 +1,15 @@
1
+ import { s as SortParams } from "./index-DpbbjAwO.cjs";
2
+ import * as _$zod from "zod";
3
+ import { z } from "zod";
4
+
5
+ //#region src/adapters/hono/parse-query.d.ts
6
+ declare function parsePaginationFromQuery(query: Record<string, string | undefined>, schema: z.ZodObject<Record<string, z.ZodTypeAny>>): Record<string, unknown>;
7
+ declare function parseSortFromQuery(query: Record<string, string | undefined>, allowedFields?: readonly string[]): SortParams;
8
+ //#endregion
9
+ //#region src/adapters/hono/types.d.ts
10
+ type HonoParseQueryOptions = {
11
+ paginationSchema?: _$zod.ZodObject<Record<string, _$zod.ZodTypeAny>>;
12
+ sortFields?: readonly string[];
13
+ };
14
+ //#endregion
15
+ export { type HonoParseQueryOptions, parsePaginationFromQuery, parseSortFromQuery };
@@ -0,0 +1,15 @@
1
+ import { s as SortParams } from "./index-C4IwIpFc.mjs";
2
+ import * as _$zod from "zod";
3
+ import { z } from "zod";
4
+
5
+ //#region src/adapters/hono/parse-query.d.ts
6
+ declare function parsePaginationFromQuery(query: Record<string, string | undefined>, schema: z.ZodObject<Record<string, z.ZodTypeAny>>): Record<string, unknown>;
7
+ declare function parseSortFromQuery(query: Record<string, string | undefined>, allowedFields?: readonly string[]): SortParams;
8
+ //#endregion
9
+ //#region src/adapters/hono/types.d.ts
10
+ type HonoParseQueryOptions = {
11
+ paginationSchema?: _$zod.ZodObject<Record<string, _$zod.ZodTypeAny>>;
12
+ sortFields?: readonly string[];
13
+ };
14
+ //#endregion
15
+ export { type HonoParseQueryOptions, parsePaginationFromQuery, parseSortFromQuery };
package/dist/hono.mjs ADDED
@@ -0,0 +1 @@
1
+ import{z as e}from"zod";function t(e){if(e===void 0)return;let t=Number(e);return Number.isNaN(t)?void 0:t}function n(n,r){let i=r.shape,a={};for(let[r]of Object.entries(i))if(n[r]!==void 0){let o=i[r];o instanceof e.ZodNumber||o instanceof e.ZodOptional&&o.unwrap()instanceof e.ZodNumber?a[r]=t(n[r]):a[r]=n[r]}return r.parse(a)}function r(e,t){let n=e.sortBy,r=e.sortOrder;if(n&&t&&!t.includes(n))return{};if(r&&r!==`asc`&&r!==`desc`)return{sortBy:n};let i={};return n&&(i.sortBy=n),r&&(i.sortOrder=r),i}export{n as parsePaginationFromQuery,r as parseSortFromQuery};
@@ -0,0 +1,199 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas/pagination.schemas.d.ts
4
+ declare const PaginationDefaultsSchema: z.ZodObject<{
5
+ page: z.ZodLiteral<1>;
6
+ pageSize: z.ZodLiteral<20>;
7
+ maxPageSize: z.ZodLiteral<100>;
8
+ minPageSize: z.ZodLiteral<1>;
9
+ }, z.core.$strip>;
10
+ type PaginationDefaults = z.infer<typeof PaginationDefaultsSchema>;
11
+ declare const PaginationParamsSchema: z.ZodObject<{
12
+ page: z.ZodOptional<z.ZodNumber>;
13
+ pageSize: z.ZodOptional<z.ZodNumber>;
14
+ }, z.core.$strip>;
15
+ type PaginationParams = z.infer<typeof PaginationParamsSchema>;
16
+ declare const OffsetPaginationParamsSchema: z.ZodObject<{
17
+ limit: z.ZodOptional<z.ZodNumber>;
18
+ offset: z.ZodOptional<z.ZodNumber>;
19
+ }, z.core.$strip>;
20
+ type OffsetPaginationParams = z.infer<typeof OffsetPaginationParamsSchema>;
21
+ declare const CursorPaginationParamsSchema: z.ZodObject<{
22
+ cursor: z.ZodOptional<z.ZodString>;
23
+ limit: z.ZodOptional<z.ZodNumber>;
24
+ }, z.core.$strip>;
25
+ type CursorPaginationParams = z.infer<typeof CursorPaginationParamsSchema>;
26
+ type CreatePaginationSchemaOptions = {
27
+ mode: 'page' | 'offset' | 'cursor';
28
+ pageSizeField?: string;
29
+ cursorField?: string;
30
+ fields?: {
31
+ page?: boolean;
32
+ pageSize?: boolean;
33
+ limit?: boolean;
34
+ offset?: boolean;
35
+ cursor?: boolean;
36
+ };
37
+ };
38
+ declare function createPaginationSchema(options: CreatePaginationSchemaOptions): z.ZodObject<{
39
+ page: z.ZodOptional<z.ZodNumber>;
40
+ } | {
41
+ page?: undefined;
42
+ }, z.core.$strip> | z.ZodObject<{
43
+ limit: z.ZodOptional<z.ZodNumber>;
44
+ } | {
45
+ limit?: undefined;
46
+ }, z.core.$strip>;
47
+ //#endregion
48
+ //#region src/types/pagination.types.d.ts
49
+ declare const PAGINATION_DEFAULTS: {
50
+ readonly page: 1;
51
+ readonly pageSize: 20;
52
+ readonly maxPageSize: 100;
53
+ readonly minPageSize: 1;
54
+ };
55
+ //#endregion
56
+ //#region src/schemas/result.schemas.d.ts
57
+ declare function createPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
58
+ items: z.ZodArray<T>;
59
+ total: z.ZodNumber;
60
+ page: z.ZodNumber;
61
+ pageSize: z.ZodNumber;
62
+ totalPages: z.ZodNumber;
63
+ hasNextPage: z.ZodBoolean;
64
+ hasPreviousPage: z.ZodBoolean;
65
+ }, z.core.$strip>;
66
+ type PaginatedResult<T> = {
67
+ items: T[];
68
+ total: number;
69
+ page: number;
70
+ pageSize: number;
71
+ totalPages: number;
72
+ hasNextPage: boolean;
73
+ hasPreviousPage: boolean;
74
+ };
75
+ declare function createOffsetPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
76
+ items: z.ZodArray<T>;
77
+ total: z.ZodNumber;
78
+ limit: z.ZodNumber;
79
+ offset: z.ZodNumber;
80
+ hasMore: z.ZodBoolean;
81
+ }, z.core.$strip>;
82
+ type OffsetPaginatedResult<T> = {
83
+ items: T[];
84
+ total: number;
85
+ limit: number;
86
+ offset: number;
87
+ hasMore: boolean;
88
+ };
89
+ declare function createCursorPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
90
+ items: z.ZodArray<T>;
91
+ nextCursor: z.ZodNullable<z.ZodString>;
92
+ previousCursor: z.ZodNullable<z.ZodString>;
93
+ hasMore: z.ZodBoolean;
94
+ }, z.core.$strip>;
95
+ type CursorPaginatedResult<T> = {
96
+ items: T[];
97
+ nextCursor: string | null;
98
+ previousCursor: string | null;
99
+ hasMore: boolean;
100
+ };
101
+ type CompactPaginatedResult<T> = {
102
+ items: T[];
103
+ total: number;
104
+ hasMore: boolean;
105
+ };
106
+ declare function createCompactPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
107
+ items: z.ZodArray<T>;
108
+ total: z.ZodNumber;
109
+ hasMore: z.ZodBoolean;
110
+ }, z.core.$strip>;
111
+ type CreateResultSchemaOptions = {
112
+ mode: 'page' | 'offset' | 'cursor' | 'compact';
113
+ pageSizeField?: string;
114
+ metadata?: ('total' | 'totalPages' | 'hasNextPage' | 'hasPreviousPage' | 'hasMore')[];
115
+ };
116
+ declare function createResultSchema<T extends z.ZodTypeAny>(itemSchema: T, options: CreateResultSchemaOptions): z.ZodObject<{
117
+ [x: string]: z.ZodNumber | z.ZodBoolean | z.ZodArray<T>;
118
+ items: z.ZodArray<T>;
119
+ total: z.ZodNumber;
120
+ page: z.ZodNumber;
121
+ totalPages: z.ZodNumber;
122
+ hasNextPage: z.ZodBoolean;
123
+ hasPreviousPage: z.ZodBoolean;
124
+ }, z.core.$strip> | z.ZodObject<{
125
+ items: z.ZodArray<T>;
126
+ nextCursor: z.ZodNullable<z.ZodString>;
127
+ previousCursor: z.ZodNullable<z.ZodString>;
128
+ hasMore: z.ZodBoolean;
129
+ }, z.core.$strip> | z.ZodObject<{
130
+ items: z.ZodArray<T>;
131
+ total: z.ZodNumber;
132
+ hasMore: z.ZodBoolean;
133
+ }, z.core.$strip>;
134
+ //#endregion
135
+ //#region src/schemas/sort.schemas.d.ts
136
+ declare const SortOrderSchema: z.ZodEnum<{
137
+ asc: "asc";
138
+ desc: "desc";
139
+ }>;
140
+ type SortOrder = z.infer<typeof SortOrderSchema>;
141
+ type SortParams<T extends string = string> = {
142
+ sortBy?: T;
143
+ sortOrder?: SortOrder;
144
+ };
145
+ declare function createSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
146
+ sortBy: z.ZodOptional<z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>>;
147
+ sortOrder: z.ZodOptional<z.ZodEnum<{
148
+ asc: "asc";
149
+ desc: "desc";
150
+ }>>;
151
+ }, z.core.$strip>;
152
+ declare const SortParamsSchema: z.ZodObject<{
153
+ sortBy: z.ZodOptional<z.ZodString>;
154
+ sortOrder: z.ZodOptional<z.ZodEnum<{
155
+ asc: "asc";
156
+ desc: "desc";
157
+ }>>;
158
+ }, z.core.$strip>;
159
+ type SortItem<T extends string = string> = {
160
+ field: T;
161
+ order: SortOrder;
162
+ };
163
+ declare function createSortItemSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
164
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
165
+ order: z.ZodEnum<{
166
+ asc: "asc";
167
+ desc: "desc";
168
+ }>;
169
+ }, z.core.$strip>;
170
+ declare const SortItemSchema: z.ZodObject<{
171
+ field: z.ZodString;
172
+ order: z.ZodEnum<{
173
+ asc: "asc";
174
+ desc: "desc";
175
+ }>;
176
+ }, z.core.$strip>;
177
+ type MultiSortParams<T extends string = string> = {
178
+ sort?: SortItem<T>[];
179
+ };
180
+ declare function createMultiSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
181
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
182
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
183
+ order: z.ZodEnum<{
184
+ asc: "asc";
185
+ desc: "desc";
186
+ }>;
187
+ }, z.core.$strip>>>;
188
+ }, z.core.$strip>;
189
+ declare const MultiSortParamsSchema: z.ZodObject<{
190
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
191
+ field: z.ZodString;
192
+ order: z.ZodEnum<{
193
+ asc: "asc";
194
+ desc: "desc";
195
+ }>;
196
+ }, z.core.$strip>>>;
197
+ }, z.core.$strip>;
198
+ //#endregion
199
+ export { createPaginationSchema as A, CursorPaginationParamsSchema as C, PaginationDefaultsSchema as D, PaginationDefaults as E, PaginationParams as O, CursorPaginationParams as S, OffsetPaginationParamsSchema as T, createCursorPaginatedResultSchema as _, SortOrder as a, createResultSchema as b, SortParamsSchema as c, createSortParamsSchema as d, CompactPaginatedResult as f, createCompactPaginatedResultSchema as g, PaginatedResult as h, SortItemSchema as i, PaginationParamsSchema as k, createMultiSortParamsSchema as l, OffsetPaginatedResult as m, MultiSortParamsSchema as n, SortOrderSchema as o, CursorPaginatedResult as p, SortItem as r, SortParams as s, MultiSortParams as t, createSortItemSchema as u, createOffsetPaginatedResultSchema as v, OffsetPaginationParams as w, PAGINATION_DEFAULTS as x, createPaginatedResultSchema as y };
@@ -0,0 +1,199 @@
1
+ import { z } from "zod";
2
+
3
+ //#region src/schemas/pagination.schemas.d.ts
4
+ declare const PaginationDefaultsSchema: z.ZodObject<{
5
+ page: z.ZodLiteral<1>;
6
+ pageSize: z.ZodLiteral<20>;
7
+ maxPageSize: z.ZodLiteral<100>;
8
+ minPageSize: z.ZodLiteral<1>;
9
+ }, z.core.$strip>;
10
+ type PaginationDefaults = z.infer<typeof PaginationDefaultsSchema>;
11
+ declare const PaginationParamsSchema: z.ZodObject<{
12
+ page: z.ZodOptional<z.ZodNumber>;
13
+ pageSize: z.ZodOptional<z.ZodNumber>;
14
+ }, z.core.$strip>;
15
+ type PaginationParams = z.infer<typeof PaginationParamsSchema>;
16
+ declare const OffsetPaginationParamsSchema: z.ZodObject<{
17
+ limit: z.ZodOptional<z.ZodNumber>;
18
+ offset: z.ZodOptional<z.ZodNumber>;
19
+ }, z.core.$strip>;
20
+ type OffsetPaginationParams = z.infer<typeof OffsetPaginationParamsSchema>;
21
+ declare const CursorPaginationParamsSchema: z.ZodObject<{
22
+ cursor: z.ZodOptional<z.ZodString>;
23
+ limit: z.ZodOptional<z.ZodNumber>;
24
+ }, z.core.$strip>;
25
+ type CursorPaginationParams = z.infer<typeof CursorPaginationParamsSchema>;
26
+ type CreatePaginationSchemaOptions = {
27
+ mode: 'page' | 'offset' | 'cursor';
28
+ pageSizeField?: string;
29
+ cursorField?: string;
30
+ fields?: {
31
+ page?: boolean;
32
+ pageSize?: boolean;
33
+ limit?: boolean;
34
+ offset?: boolean;
35
+ cursor?: boolean;
36
+ };
37
+ };
38
+ declare function createPaginationSchema(options: CreatePaginationSchemaOptions): z.ZodObject<{
39
+ page: z.ZodOptional<z.ZodNumber>;
40
+ } | {
41
+ page?: undefined;
42
+ }, z.core.$strip> | z.ZodObject<{
43
+ limit: z.ZodOptional<z.ZodNumber>;
44
+ } | {
45
+ limit?: undefined;
46
+ }, z.core.$strip>;
47
+ //#endregion
48
+ //#region src/types/pagination.types.d.ts
49
+ declare const PAGINATION_DEFAULTS: {
50
+ readonly page: 1;
51
+ readonly pageSize: 20;
52
+ readonly maxPageSize: 100;
53
+ readonly minPageSize: 1;
54
+ };
55
+ //#endregion
56
+ //#region src/schemas/result.schemas.d.ts
57
+ declare function createPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
58
+ items: z.ZodArray<T>;
59
+ total: z.ZodNumber;
60
+ page: z.ZodNumber;
61
+ pageSize: z.ZodNumber;
62
+ totalPages: z.ZodNumber;
63
+ hasNextPage: z.ZodBoolean;
64
+ hasPreviousPage: z.ZodBoolean;
65
+ }, z.core.$strip>;
66
+ type PaginatedResult<T> = {
67
+ items: T[];
68
+ total: number;
69
+ page: number;
70
+ pageSize: number;
71
+ totalPages: number;
72
+ hasNextPage: boolean;
73
+ hasPreviousPage: boolean;
74
+ };
75
+ declare function createOffsetPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
76
+ items: z.ZodArray<T>;
77
+ total: z.ZodNumber;
78
+ limit: z.ZodNumber;
79
+ offset: z.ZodNumber;
80
+ hasMore: z.ZodBoolean;
81
+ }, z.core.$strip>;
82
+ type OffsetPaginatedResult<T> = {
83
+ items: T[];
84
+ total: number;
85
+ limit: number;
86
+ offset: number;
87
+ hasMore: boolean;
88
+ };
89
+ declare function createCursorPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
90
+ items: z.ZodArray<T>;
91
+ nextCursor: z.ZodNullable<z.ZodString>;
92
+ previousCursor: z.ZodNullable<z.ZodString>;
93
+ hasMore: z.ZodBoolean;
94
+ }, z.core.$strip>;
95
+ type CursorPaginatedResult<T> = {
96
+ items: T[];
97
+ nextCursor: string | null;
98
+ previousCursor: string | null;
99
+ hasMore: boolean;
100
+ };
101
+ type CompactPaginatedResult<T> = {
102
+ items: T[];
103
+ total: number;
104
+ hasMore: boolean;
105
+ };
106
+ declare function createCompactPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
107
+ items: z.ZodArray<T>;
108
+ total: z.ZodNumber;
109
+ hasMore: z.ZodBoolean;
110
+ }, z.core.$strip>;
111
+ type CreateResultSchemaOptions = {
112
+ mode: 'page' | 'offset' | 'cursor' | 'compact';
113
+ pageSizeField?: string;
114
+ metadata?: ('total' | 'totalPages' | 'hasNextPage' | 'hasPreviousPage' | 'hasMore')[];
115
+ };
116
+ declare function createResultSchema<T extends z.ZodTypeAny>(itemSchema: T, options: CreateResultSchemaOptions): z.ZodObject<{
117
+ [x: string]: z.ZodNumber | z.ZodBoolean | z.ZodArray<T>;
118
+ items: z.ZodArray<T>;
119
+ total: z.ZodNumber;
120
+ page: z.ZodNumber;
121
+ totalPages: z.ZodNumber;
122
+ hasNextPage: z.ZodBoolean;
123
+ hasPreviousPage: z.ZodBoolean;
124
+ }, z.core.$strip> | z.ZodObject<{
125
+ items: z.ZodArray<T>;
126
+ nextCursor: z.ZodNullable<z.ZodString>;
127
+ previousCursor: z.ZodNullable<z.ZodString>;
128
+ hasMore: z.ZodBoolean;
129
+ }, z.core.$strip> | z.ZodObject<{
130
+ items: z.ZodArray<T>;
131
+ total: z.ZodNumber;
132
+ hasMore: z.ZodBoolean;
133
+ }, z.core.$strip>;
134
+ //#endregion
135
+ //#region src/schemas/sort.schemas.d.ts
136
+ declare const SortOrderSchema: z.ZodEnum<{
137
+ asc: "asc";
138
+ desc: "desc";
139
+ }>;
140
+ type SortOrder = z.infer<typeof SortOrderSchema>;
141
+ type SortParams<T extends string = string> = {
142
+ sortBy?: T;
143
+ sortOrder?: SortOrder;
144
+ };
145
+ declare function createSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
146
+ sortBy: z.ZodOptional<z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>>;
147
+ sortOrder: z.ZodOptional<z.ZodEnum<{
148
+ asc: "asc";
149
+ desc: "desc";
150
+ }>>;
151
+ }, z.core.$strip>;
152
+ declare const SortParamsSchema: z.ZodObject<{
153
+ sortBy: z.ZodOptional<z.ZodString>;
154
+ sortOrder: z.ZodOptional<z.ZodEnum<{
155
+ asc: "asc";
156
+ desc: "desc";
157
+ }>>;
158
+ }, z.core.$strip>;
159
+ type SortItem<T extends string = string> = {
160
+ field: T;
161
+ order: SortOrder;
162
+ };
163
+ declare function createSortItemSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
164
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
165
+ order: z.ZodEnum<{
166
+ asc: "asc";
167
+ desc: "desc";
168
+ }>;
169
+ }, z.core.$strip>;
170
+ declare const SortItemSchema: z.ZodObject<{
171
+ field: z.ZodString;
172
+ order: z.ZodEnum<{
173
+ asc: "asc";
174
+ desc: "desc";
175
+ }>;
176
+ }, z.core.$strip>;
177
+ type MultiSortParams<T extends string = string> = {
178
+ sort?: SortItem<T>[];
179
+ };
180
+ declare function createMultiSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
181
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
182
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
183
+ order: z.ZodEnum<{
184
+ asc: "asc";
185
+ desc: "desc";
186
+ }>;
187
+ }, z.core.$strip>>>;
188
+ }, z.core.$strip>;
189
+ declare const MultiSortParamsSchema: z.ZodObject<{
190
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
191
+ field: z.ZodString;
192
+ order: z.ZodEnum<{
193
+ asc: "asc";
194
+ desc: "desc";
195
+ }>;
196
+ }, z.core.$strip>>>;
197
+ }, z.core.$strip>;
198
+ //#endregion
199
+ export { createPaginationSchema as A, CursorPaginationParamsSchema as C, PaginationDefaultsSchema as D, PaginationDefaults as E, PaginationParams as O, CursorPaginationParams as S, OffsetPaginationParamsSchema as T, createCursorPaginatedResultSchema as _, SortOrder as a, createResultSchema as b, SortParamsSchema as c, createSortParamsSchema as d, CompactPaginatedResult as f, createCompactPaginatedResultSchema as g, PaginatedResult as h, SortItemSchema as i, PaginationParamsSchema as k, createMultiSortParamsSchema as l, OffsetPaginatedResult as m, MultiSortParamsSchema as n, SortOrderSchema as o, CursorPaginatedResult as p, SortItem as r, SortParams as s, MultiSortParams as t, createSortItemSchema as u, createOffsetPaginatedResultSchema as v, OffsetPaginationParams as w, PAGINATION_DEFAULTS as x, createPaginatedResultSchema as y };