@longzai-intelligence/pagination 0.0.2 → 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 (91) hide show
  1. package/README.md +36 -207
  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-C8FaNzej.d.mts → index-C4IwIpFc.d.mts} +55 -1
  7. package/dist/{index-CMiyhlfm.d.cts → index-DpbbjAwO.d.cts} +55 -1
  8. package/dist/index.cjs +1 -33
  9. package/dist/index.d.cts +80 -2
  10. package/dist/index.d.mts +80 -2
  11. package/dist/index.mjs +1 -1
  12. package/dist/typeorm.cjs +1 -129
  13. package/dist/typeorm.d.cts +1 -1
  14. package/dist/typeorm.d.mts +1 -1
  15. package/dist/typeorm.mjs +1 -1
  16. package/dist/utils-B200OLT-.cjs +1 -0
  17. package/dist/utils-DsM7-PZL.mjs +1 -0
  18. package/package.json +19 -7
  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 -18
  25. package/coverage/base.css +0 -224
  26. package/coverage/block-navigation.js +0 -87
  27. package/coverage/coverage-final.json +0 -16
  28. package/coverage/favicon.png +0 -0
  29. package/coverage/index.html +0 -176
  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 -116
  35. package/coverage/src/adapters/typeorm.adapter.ts.html +0 -940
  36. package/coverage/src/index.html +0 -131
  37. package/coverage/src/index.ts.html +0 -280
  38. package/coverage/src/schemas/index.html +0 -161
  39. package/coverage/src/schemas/index.ts.html +0 -169
  40. package/coverage/src/schemas/pagination.schemas.ts.html +0 -343
  41. package/coverage/src/schemas/result.schemas.ts.html +0 -724
  42. package/coverage/src/schemas/sort.schemas.ts.html +0 -544
  43. package/coverage/src/typeorm.ts.html +0 -154
  44. package/coverage/src/types/index.html +0 -176
  45. package/coverage/src/types/index.ts.html +0 -199
  46. package/coverage/src/types/pagination.types.ts.html +0 -169
  47. package/coverage/src/types/result.types.ts.html +0 -127
  48. package/coverage/src/types/sort.types.ts.html +0 -142
  49. package/coverage/src/types/typeorm.d.ts.html +0 -196
  50. package/coverage/src/utils/index.html +0 -146
  51. package/coverage/src/utils/index.ts.html +0 -178
  52. package/coverage/src/utils/pagination.util.ts.html +0 -703
  53. package/coverage/src/utils/validation.util.ts.html +0 -535
  54. package/dist/utils-CV6Ovku6.mjs +0 -1
  55. package/dist/utils-D_qD2YAX.cjs +0 -1
  56. package/docs/specs/spec-20260413-typeorm-subpath-export/checklist.md +0 -33
  57. package/docs/specs/spec-20260413-typeorm-subpath-export/spec.md +0 -104
  58. package/docs/specs/spec-20260413-typeorm-subpath-export/tasks.md +0 -48
  59. package/eslint.config.ts +0 -3
  60. package/src/__tests__/index.test.ts +0 -72
  61. package/src/__tests__/pagination.util.test.ts +0 -251
  62. package/src/__tests__/result.schemas.test.ts +0 -142
  63. package/src/__tests__/sort.schemas.test.ts +0 -157
  64. package/src/__tests__/typeorm.adapter.test.ts +0 -212
  65. package/src/__tests__/validation.util.test.ts +0 -120
  66. package/src/adapters/typeorm/adapter.ts +0 -203
  67. package/src/adapters/typeorm/index.ts +0 -23
  68. package/src/adapters/typeorm/typeorm.d.ts +0 -37
  69. package/src/adapters/typeorm/types.ts +0 -95
  70. package/src/index.ts +0 -65
  71. package/src/schemas/index.ts +0 -28
  72. package/src/schemas/pagination.schemas.ts +0 -86
  73. package/src/schemas/result.schemas.ts +0 -213
  74. package/src/schemas/sort.schemas.ts +0 -153
  75. package/src/typeorm.ts +0 -23
  76. package/src/types/index.ts +0 -38
  77. package/src/types/pagination.types.ts +0 -28
  78. package/src/types/result.types.ts +0 -14
  79. package/src/types/sort.types.ts +0 -19
  80. package/src/utils/index.ts +0 -31
  81. package/src/utils/pagination.util.ts +0 -206
  82. package/src/utils/validation.util.ts +0 -150
  83. package/tsconfig/.cache/app.tsbuildinfo +0 -1
  84. package/tsconfig/.cache/node.tsbuildinfo +0 -1
  85. package/tsconfig/.cache/test.tsbuildinfo +0 -1
  86. package/tsconfig/app.json +0 -15
  87. package/tsconfig/node.json +0 -11
  88. package/tsconfig/test.json +0 -14
  89. package/tsconfig.json +0 -9
  90. package/tsdown.config.ts +0 -13
  91. package/vitest.config.ts +0 -3
@@ -1,38 +0,0 @@
1
- /**
2
- * 类型导出入口
3
- */
4
-
5
- export type {
6
- PaginationParams,
7
- OffsetPaginationParams,
8
- CursorPaginationParams,
9
- PaginationDefaults,
10
- } from './pagination.types';
11
-
12
- export {
13
- PAGINATION_DEFAULTS,
14
- PaginationDefaultsSchema,
15
- PaginationParamsSchema,
16
- OffsetPaginationParamsSchema,
17
- CursorPaginationParamsSchema,
18
- } from './pagination.types';
19
-
20
- export type { PaginatedResult, OffsetPaginatedResult, CursorPaginatedResult } from './result.types';
21
-
22
- export {
23
- createPaginatedResultSchema,
24
- createOffsetPaginatedResultSchema,
25
- createCursorPaginatedResultSchema,
26
- } from './result.types';
27
-
28
- export type { SortOrder, SortParams, SortItem, MultiSortParams } from './sort.types';
29
-
30
- export {
31
- SortOrderSchema,
32
- SortParamsSchema,
33
- SortItemSchema,
34
- MultiSortParamsSchema,
35
- createSortParamsSchema,
36
- createSortItemSchema,
37
- createMultiSortParamsSchema,
38
- } from './sort.types';
@@ -1,28 +0,0 @@
1
- /**
2
- * 分页参数类型定义
3
- *
4
- * 类型从 zod schemas 推导导出
5
- */
6
-
7
- export {
8
- PaginationDefaultsSchema,
9
- PaginationParamsSchema,
10
- OffsetPaginationParamsSchema,
11
- CursorPaginationParamsSchema,
12
- type PaginationDefaults,
13
- type PaginationParams,
14
- type OffsetPaginationParams,
15
- type CursorPaginationParams,
16
- } from '../schemas/pagination.schemas';
17
-
18
- /**
19
- * 默认分页配置值
20
- *
21
- * 用于运行时验证和默认值设置
22
- */
23
- export const PAGINATION_DEFAULTS = {
24
- page: 1,
25
- pageSize: 20,
26
- maxPageSize: 100,
27
- minPageSize: 1,
28
- } as const;
@@ -1,14 +0,0 @@
1
- /**
2
- * 分页结果类型定义
3
- *
4
- * 类型从 zod schemas 推导导出
5
- */
6
-
7
- export {
8
- createPaginatedResultSchema,
9
- createOffsetPaginatedResultSchema,
10
- createCursorPaginatedResultSchema,
11
- type PaginatedResult,
12
- type OffsetPaginatedResult,
13
- type CursorPaginatedResult,
14
- } from '../schemas/result.schemas';
@@ -1,19 +0,0 @@
1
- /**
2
- * 排序类型定义
3
- *
4
- * 类型从 zod schemas 推导导出
5
- */
6
-
7
- export {
8
- SortOrderSchema,
9
- SortParamsSchema,
10
- SortItemSchema,
11
- MultiSortParamsSchema,
12
- createSortParamsSchema,
13
- createSortItemSchema,
14
- createMultiSortParamsSchema,
15
- type SortOrder,
16
- type SortParams,
17
- type SortItem,
18
- type MultiSortParams,
19
- } from '../schemas/sort.schemas';
@@ -1,31 +0,0 @@
1
- /**
2
- * 工具函数导出入口
3
- */
4
-
5
- export type { OffsetPaginationResult, PagePaginationResult } from './pagination.util';
6
-
7
- export type {
8
- PaginationValidationResult,
9
- OffsetPaginationValidationResult,
10
- } from './validation.util';
11
-
12
- export {
13
- normalizePagination,
14
- normalizeOffsetPagination,
15
- calculateOffset,
16
- calculateTotalPages,
17
- hasNextPage,
18
- hasPreviousPage,
19
- offsetToPage,
20
- pageToOffset,
21
- createPaginatedResult,
22
- } from './pagination.util';
23
-
24
- export {
25
- isValidPage,
26
- isValidPageSize,
27
- isValidOffset,
28
- isValidLimit,
29
- isValidPagination,
30
- isValidOffsetPagination,
31
- } from './validation.util';
@@ -1,206 +0,0 @@
1
- /**
2
- * 分页计算工具函数
3
- */
4
-
5
- import { PAGINATION_DEFAULTS, type PaginationParams, type OffsetPaginationParams } from '../types';
6
-
7
- /**
8
- * Offset 风格分页参数
9
- */
10
- export type OffsetPaginationResult = {
11
- /**
12
- * 页码
13
- */
14
- page: number;
15
-
16
- /**
17
- * 每页数量
18
- */
19
- pageSize: number;
20
- };
21
-
22
- /**
23
- * Page 风格分页参数
24
- */
25
- export type PagePaginationResult = {
26
- /**
27
- * 偏移量
28
- */
29
- offset: number;
30
-
31
- /**
32
- * 限制数量
33
- */
34
- limit: number;
35
- };
36
-
37
- /**
38
- * 规范化分页参数
39
- * 确保参数在有效范围内
40
- *
41
- * @param params - 原始分页参数
42
- * @returns 规范化后的分页参数
43
- */
44
- export function normalizePagination(params?: PaginationParams): Required<PaginationParams> {
45
- /**
46
- * 规范化后的页码
47
- */
48
- const page = Math.max(1, Math.floor(params?.page ?? PAGINATION_DEFAULTS.page));
49
-
50
- /**
51
- * 规范化后的每页数量
52
- */
53
- const pageSize = Math.min(
54
- PAGINATION_DEFAULTS.maxPageSize,
55
- Math.max(
56
- PAGINATION_DEFAULTS.minPageSize,
57
- Math.floor(params?.pageSize ?? PAGINATION_DEFAULTS.pageSize),
58
- ),
59
- );
60
- return { page, pageSize };
61
- }
62
-
63
- /**
64
- * 规范化 offset 分页参数
65
- *
66
- * @param params - 原始 offset 分页参数
67
- * @returns 规范化后的 offset 分页参数
68
- */
69
- export function normalizeOffsetPagination(
70
- params?: OffsetPaginationParams,
71
- ): Required<OffsetPaginationParams> {
72
- /**
73
- * 规范化后的限制数量
74
- */
75
- const limit = Math.min(
76
- PAGINATION_DEFAULTS.maxPageSize,
77
- Math.max(
78
- PAGINATION_DEFAULTS.minPageSize,
79
- Math.floor(params?.limit ?? PAGINATION_DEFAULTS.pageSize),
80
- ),
81
- );
82
-
83
- /**
84
- * 规范化后的偏移量
85
- */
86
- const offset = Math.max(0, Math.floor(params?.offset ?? 0));
87
- return { limit, offset };
88
- }
89
-
90
- /**
91
- * 计算偏移量
92
- *
93
- * @param page - 页码(从 1 开始)
94
- * @param pageSize - 每页数量
95
- * @returns 偏移量
96
- */
97
- export function calculateOffset(page: number, pageSize: number): number {
98
- return (page - 1) * pageSize;
99
- }
100
-
101
- /**
102
- * 计算总页数
103
- *
104
- * @param total - 总记录数
105
- * @param pageSize - 每页数量
106
- * @returns 总页数
107
- */
108
- export function calculateTotalPages(total: number, pageSize: number): number {
109
- if (pageSize <= 0) {
110
- return 0;
111
- }
112
- return Math.ceil(total / pageSize);
113
- }
114
-
115
- /**
116
- * 判断是否有下一页
117
- *
118
- * @param page - 当前页码
119
- * @param totalPages - 总页数
120
- * @returns 是否有下一页
121
- */
122
- export function hasNextPage(page: number, totalPages: number): boolean {
123
- return page < totalPages;
124
- }
125
-
126
- /**
127
- * 判断是否有上一页
128
- *
129
- * @param page - 当前页码
130
- * @returns 是否有上一页
131
- */
132
- export function hasPreviousPage(page: number): boolean {
133
- return page > 1;
134
- }
135
-
136
- /**
137
- * offset 风格转 page 风格
138
- *
139
- * @param offset - 偏移量
140
- * @param limit - 每页数量
141
- * @returns page 风格参数
142
- */
143
- export function offsetToPage(offset: number, limit: number): OffsetPaginationResult {
144
- /**
145
- * 规范化后的限制数量
146
- */
147
- const safeLimit = Math.max(1, limit);
148
- return {
149
- page: Math.floor(offset / safeLimit) + 1,
150
- pageSize: safeLimit,
151
- };
152
- }
153
-
154
- /**
155
- * page 风格转 offset 风格
156
- *
157
- * @param page - 页码
158
- * @param pageSize - 每页数量
159
- * @returns offset 风格参数
160
- */
161
- export function pageToOffset(page: number, pageSize: number): PagePaginationResult {
162
- /**
163
- * 规范化后的页码
164
- */
165
- const safePage = Math.max(1, page);
166
-
167
- /**
168
- * 规范化后的每页数量
169
- */
170
- const safePageSize = Math.max(1, pageSize);
171
- return {
172
- offset: (safePage - 1) * safePageSize,
173
- limit: safePageSize,
174
- };
175
- }
176
-
177
- /**
178
- * 创建分页结果对象
179
- *
180
- * @typeParam T - 数据项类型
181
- * @param items - 数据项数组
182
- * @param total - 总记录数
183
- * @param page - 当前页码
184
- * @param pageSize - 每页数量
185
- * @returns 分页结果
186
- */
187
- export function createPaginatedResult<T>(
188
- items: T[],
189
- total: number,
190
- page: number,
191
- pageSize: number,
192
- ): import('../types').PaginatedResult<T> {
193
- /**
194
- * 计算的总页数
195
- */
196
- const totalPages = calculateTotalPages(total, pageSize);
197
- return {
198
- items,
199
- total,
200
- page,
201
- pageSize,
202
- totalPages,
203
- hasNextPage: hasNextPage(page, totalPages),
204
- hasPreviousPage: hasPreviousPage(page),
205
- };
206
- }
@@ -1,150 +0,0 @@
1
- /**
2
- * 分页参数验证工具函数
3
- */
4
-
5
- import { PAGINATION_DEFAULTS } from '../types';
6
-
7
- /**
8
- * 检查值是否为对象类型
9
- *
10
- * @param value - 待检查的值
11
- * @returns 是否为对象类型
12
- */
13
- function isObject(value: unknown): value is Record<string, unknown> {
14
- return typeof value === 'object' && value !== null;
15
- }
16
-
17
- /**
18
- * Page 风格分页参数
19
- */
20
- export type PaginationValidationResult = {
21
- /**
22
- * 页码
23
- */
24
- page: number;
25
-
26
- /**
27
- * 每页数量
28
- */
29
- pageSize: number;
30
- };
31
-
32
- /**
33
- * Offset 风格分页参数
34
- */
35
- export type OffsetPaginationValidationResult = {
36
- /**
37
- * 限制数量
38
- */
39
- limit: number;
40
-
41
- /**
42
- * 偏移量
43
- */
44
- offset: number;
45
- };
46
-
47
- /**
48
- * 验证页码是否有效
49
- *
50
- * @param page - 页码
51
- * @returns 是否有效
52
- */
53
- export function isValidPage(page: unknown): page is number {
54
- return typeof page === 'number' && Number.isInteger(page) && page >= 1;
55
- }
56
-
57
- /**
58
- * 验证每页数量是否有效
59
- *
60
- * @param pageSize - 每页数量
61
- * @returns 是否有效
62
- */
63
- export function isValidPageSize(pageSize: unknown): pageSize is number {
64
- return (
65
- typeof pageSize === 'number' &&
66
- Number.isInteger(pageSize) &&
67
- pageSize >= PAGINATION_DEFAULTS.minPageSize &&
68
- pageSize <= PAGINATION_DEFAULTS.maxPageSize
69
- );
70
- }
71
-
72
- /**
73
- * 验证偏移量是否有效
74
- *
75
- * @param offset - 偏移量
76
- * @returns 是否有效
77
- */
78
- export function isValidOffset(offset: unknown): offset is number {
79
- return typeof offset === 'number' && Number.isInteger(offset) && offset >= 0;
80
- }
81
-
82
- /**
83
- * 验证 limit 是否有效
84
- *
85
- * @param limit - 限制数量
86
- * @returns 是否有效
87
- */
88
- export function isValidLimit(limit: unknown): limit is number {
89
- return (
90
- typeof limit === 'number' &&
91
- Number.isInteger(limit) &&
92
- limit >= PAGINATION_DEFAULTS.minPageSize &&
93
- limit <= PAGINATION_DEFAULTS.maxPageSize
94
- );
95
- }
96
-
97
- /**
98
- * 验证分页参数是否有效
99
- *
100
- * @param params - 分页参数
101
- * @returns 是否有效
102
- */
103
- export function isValidPagination(params: unknown): params is PaginationValidationResult {
104
- if (!isObject(params)) {
105
- return false;
106
- }
107
-
108
- /**
109
- * 提取的页码
110
- */
111
- const page = params.page;
112
-
113
- /**
114
- * 提取的每页数量
115
- */
116
- const pageSize = params.pageSize;
117
-
118
- return (
119
- (page === undefined || isValidPage(page)) &&
120
- (pageSize === undefined || isValidPageSize(pageSize))
121
- );
122
- }
123
-
124
- /**
125
- * 验证 offset 分页参数是否有效
126
- *
127
- * @param params - offset 分页参数
128
- * @returns 是否有效
129
- */
130
- export function isValidOffsetPagination(
131
- params: unknown,
132
- ): params is OffsetPaginationValidationResult {
133
- if (!isObject(params)) {
134
- return false;
135
- }
136
-
137
- /**
138
- * 提取的限制数量
139
- */
140
- const limit = params.limit;
141
-
142
- /**
143
- * 提取的偏移量
144
- */
145
- const offset = params.offset;
146
-
147
- return (
148
- (limit === undefined || isValidLimit(limit)) && (offset === undefined || isValidOffset(offset))
149
- );
150
- }