@longzai-intelligence/pagination 0.0.1 → 0.0.2

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 (70) hide show
  1. package/.turbo/turbo-build.log +3 -3
  2. package/.turbo/turbo-test$colon$coverage.log +6 -6
  3. package/.turbo/turbo-test.log +7 -7
  4. package/CHANGELOG.md +7 -0
  5. package/README.md +5 -1
  6. package/coverage/coverage-final.json +6 -2
  7. package/coverage/index.html +19 -4
  8. package/coverage/src/adapters/index.html +1 -16
  9. package/coverage/src/adapters/typeorm.adapter.ts.html +1 -1
  10. package/coverage/src/index.html +16 -1
  11. package/coverage/src/index.ts.html +38 -11
  12. package/coverage/src/schemas/index.html +161 -0
  13. package/coverage/src/{adapters → schemas}/index.ts.html +61 -10
  14. package/coverage/src/schemas/pagination.schemas.ts.html +343 -0
  15. package/coverage/src/schemas/result.schemas.ts.html +724 -0
  16. package/coverage/src/schemas/sort.schemas.ts.html +544 -0
  17. package/coverage/src/typeorm.ts.html +154 -0
  18. package/coverage/src/types/index.html +1 -1
  19. package/coverage/src/types/index.ts.html +69 -3
  20. package/coverage/src/types/pagination.types.ts.html +15 -138
  21. package/coverage/src/types/result.types.ts.html +11 -299
  22. package/coverage/src/types/sort.types.ts.html +16 -139
  23. package/coverage/src/types/typeorm.d.ts.html +1 -1
  24. package/coverage/src/utils/index.html +1 -1
  25. package/coverage/src/utils/index.ts.html +1 -1
  26. package/coverage/src/utils/pagination.util.ts.html +1 -1
  27. package/coverage/src/utils/validation.util.ts.html +1 -1
  28. package/dist/index-C8FaNzej.d.mts +145 -0
  29. package/dist/index-CMiyhlfm.d.cts +145 -0
  30. package/dist/index.cjs +33 -1
  31. package/dist/index.d.cts +2 -81
  32. package/dist/index.d.mts +2 -81
  33. package/dist/index.mjs +1 -1
  34. package/dist/typeorm.cjs +129 -0
  35. package/dist/typeorm.d.cts +26 -0
  36. package/dist/typeorm.d.mts +26 -0
  37. package/dist/typeorm.mjs +1 -0
  38. package/dist/utils-CV6Ovku6.mjs +1 -0
  39. package/dist/utils-D_qD2YAX.cjs +1 -0
  40. package/docs/specs/spec-20260413-typeorm-subpath-export/checklist.md +33 -0
  41. package/docs/specs/spec-20260413-typeorm-subpath-export/spec.md +104 -0
  42. package/docs/specs/spec-20260413-typeorm-subpath-export/tasks.md +48 -0
  43. package/package.json +15 -3
  44. package/src/__tests__/index.test.ts +9 -3
  45. package/src/__tests__/pagination.util.test.ts +0 -2
  46. package/src/__tests__/result.schemas.test.ts +142 -0
  47. package/src/__tests__/sort.schemas.test.ts +157 -0
  48. package/src/__tests__/typeorm.adapter.test.ts +1 -3
  49. package/src/__tests__/validation.util.test.ts +0 -2
  50. package/src/adapters/{typeorm.adapter.ts → typeorm/adapter.ts} +10 -92
  51. package/src/adapters/typeorm/index.ts +23 -0
  52. package/src/adapters/typeorm/types.ts +95 -0
  53. package/src/index.ts +18 -9
  54. package/src/schemas/index.ts +28 -0
  55. package/src/schemas/pagination.schemas.ts +86 -0
  56. package/src/schemas/result.schemas.ts +213 -0
  57. package/src/schemas/sort.schemas.ts +153 -0
  58. package/src/typeorm.ts +23 -0
  59. package/src/types/index.ts +23 -1
  60. package/src/types/pagination.types.ts +13 -54
  61. package/src/types/result.types.ts +9 -105
  62. package/src/types/sort.types.ts +14 -55
  63. package/tsconfig/.cache/app.tsbuildinfo +1 -1
  64. package/tsconfig/.cache/node.tsbuildinfo +1 -1
  65. package/tsconfig/.cache/test.tsbuildinfo +1 -1
  66. package/tsconfig/app.json +4 -1
  67. package/tsdown.config.ts +10 -3
  68. package/src/adapters/index.ts +0 -11
  69. package/tsconfig/.cache/build.tsbuildinfo +0 -1
  70. /package/src/{types → adapters/typeorm}/typeorm.d.ts +0 -0
@@ -0,0 +1,153 @@
1
+ /**
2
+ * 排序参数 Zod Schema 定义
3
+ */
4
+
5
+ import { z } from 'zod';
6
+
7
+ /**
8
+ * 排序方向 Schema
9
+ */
10
+ export const SortOrderSchema = z.enum(['asc', 'desc']);
11
+
12
+ /**
13
+ * 排序方向类型
14
+ */
15
+ export type SortOrder = z.infer<typeof SortOrderSchema>;
16
+
17
+ /**
18
+ * 排序参数类型
19
+ */
20
+ export type SortParams<T extends string = string> = {
21
+ /**
22
+ * 排序字段
23
+ */
24
+ sortBy?: T;
25
+
26
+ /**
27
+ * 排序方向
28
+ */
29
+ sortOrder?: SortOrder;
30
+ };
31
+
32
+ /**
33
+ * 创建排序参数 Schema
34
+ *
35
+ * 单字段排序参数
36
+ *
37
+ * @typeParam T - 排序字段枚举类型
38
+ */
39
+ export function createSortParamsSchema<T extends [string, ...string[]]>(fields: T) {
40
+ return z.object({
41
+ /**
42
+ * 排序字段
43
+ */
44
+ sortBy: z.enum(fields).optional(),
45
+
46
+ /**
47
+ * 排序方向
48
+ */
49
+ sortOrder: SortOrderSchema.optional(),
50
+ });
51
+ }
52
+
53
+ /**
54
+ * 默认排序参数 Schema(字符串字段)
55
+ */
56
+ export const SortParamsSchema = z.object({
57
+ /**
58
+ * 排序字段
59
+ */
60
+ sortBy: z.string().optional(),
61
+
62
+ /**
63
+ * 排序方向
64
+ */
65
+ sortOrder: SortOrderSchema.optional(),
66
+ });
67
+
68
+ /**
69
+ * 多字段排序项类型
70
+ */
71
+ export type SortItem<T extends string = string> = {
72
+ /**
73
+ * 排序字段
74
+ */
75
+ field: T;
76
+
77
+ /**
78
+ * 排序方向
79
+ */
80
+ order: SortOrder;
81
+ };
82
+
83
+ /**
84
+ * 创建多字段排序项 Schema
85
+ *
86
+ * 单个排序项定义
87
+ *
88
+ * @typeParam T - 排序字段枚举类型
89
+ */
90
+ export function createSortItemSchema<T extends [string, ...string[]]>(fields: T) {
91
+ return z.object({
92
+ /**
93
+ * 排序字段
94
+ */
95
+ field: z.enum(fields),
96
+
97
+ /**
98
+ * 排序方向
99
+ */
100
+ order: SortOrderSchema,
101
+ });
102
+ }
103
+
104
+ /**
105
+ * 默认排序项 Schema(字符串字段)
106
+ */
107
+ export const SortItemSchema = z.object({
108
+ /**
109
+ * 排序字段
110
+ */
111
+ field: z.string(),
112
+
113
+ /**
114
+ * 排序方向
115
+ */
116
+ order: SortOrderSchema,
117
+ });
118
+
119
+ /**
120
+ * 多字段排序参数类型
121
+ */
122
+ export type MultiSortParams<T extends string = string> = {
123
+ /**
124
+ * 排序项数组
125
+ */
126
+ sort?: SortItem<T>[];
127
+ };
128
+
129
+ /**
130
+ * 创建多字段排序参数 Schema
131
+ *
132
+ * 支持多个字段的排序
133
+ *
134
+ * @typeParam T - 排序字段枚举类型
135
+ */
136
+ export function createMultiSortParamsSchema<T extends [string, ...string[]]>(fields: T) {
137
+ return z.object({
138
+ /**
139
+ * 排序项数组
140
+ */
141
+ sort: z.array(createSortItemSchema(fields)).optional(),
142
+ });
143
+ }
144
+
145
+ /**
146
+ * 默认多字段排序参数 Schema(字符串字段)
147
+ */
148
+ export const MultiSortParamsSchema = z.object({
149
+ /**
150
+ * 排序项数组
151
+ */
152
+ sort: z.array(SortItemSchema).optional(),
153
+ });
package/src/typeorm.ts ADDED
@@ -0,0 +1,23 @@
1
+ /**
2
+ * TypeORM 适配器入口
3
+ *
4
+ * 提供 TypeORM 分页查询功能,需要安装 typeorm 作为 peerDependency。
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { paginateWithRepository } from '@longzai-intelligence/pagination/typeorm';
9
+ *
10
+ * const result = await paginateWithRepository(userRepository, {
11
+ * page: 1,
12
+ * pageSize: 20,
13
+ * });
14
+ * ```
15
+ */
16
+
17
+ export type { EntityMapper, TypeOrmPaginateOptions } from './adapters/typeorm';
18
+
19
+ export {
20
+ paginateWithRepository,
21
+ paginateWithQueryBuilder,
22
+ createPaginationQueryBuilder,
23
+ } from './adapters/typeorm';
@@ -9,8 +9,30 @@ export type {
9
9
  PaginationDefaults,
10
10
  } from './pagination.types';
11
11
 
12
- export { PAGINATION_DEFAULTS } from './pagination.types';
12
+ export {
13
+ PAGINATION_DEFAULTS,
14
+ PaginationDefaultsSchema,
15
+ PaginationParamsSchema,
16
+ OffsetPaginationParamsSchema,
17
+ CursorPaginationParamsSchema,
18
+ } from './pagination.types';
13
19
 
14
20
  export type { PaginatedResult, OffsetPaginatedResult, CursorPaginatedResult } from './result.types';
15
21
 
22
+ export {
23
+ createPaginatedResultSchema,
24
+ createOffsetPaginatedResultSchema,
25
+ createCursorPaginatedResultSchema,
26
+ } from './result.types';
27
+
16
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,60 +1,24 @@
1
1
  /**
2
2
  * 分页参数类型定义
3
- */
4
-
5
- /**
6
- * 分页参数(page 风格,推荐使用)
7
- *
8
- * 适用于用户界面分页场景
9
- */
10
- export type PaginationParams = {
11
- /**
12
- * 页码(从 1 开始)
13
- */
14
- page?: number;
15
-
16
- /**
17
- * 每页数量
18
- */
19
- pageSize?: number;
20
- };
21
-
22
- /**
23
- * 分页参数(offset 风格)
24
3
  *
25
- * 适用于 API 调用、数据库查询等场景
4
+ * 类型从 zod schemas 推导导出
26
5
  */
27
- export type OffsetPaginationParams = {
28
- /**
29
- * 限制数量
30
- */
31
- limit?: number;
32
6
 
33
- /**
34
- * 偏移量
35
- */
36
- offset?: number;
37
- };
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';
38
17
 
39
18
  /**
40
- * 游标分页参数
19
+ * 默认分页配置值
41
20
  *
42
- * 适用于无限滚动、实时数据流场景
43
- */
44
- export type CursorPaginationParams = {
45
- /**
46
- * 游标
47
- */
48
- cursor?: string;
49
-
50
- /**
51
- * 限制数量
52
- */
53
- limit?: number;
54
- };
55
-
56
- /**
57
- * 默认分页配置
21
+ * 用于运行时验证和默认值设置
58
22
  */
59
23
  export const PAGINATION_DEFAULTS = {
60
24
  page: 1,
@@ -62,8 +26,3 @@ export const PAGINATION_DEFAULTS = {
62
26
  maxPageSize: 100,
63
27
  minPageSize: 1,
64
28
  } as const;
65
-
66
- /**
67
- * 默认分页参数类型
68
- */
69
- export type PaginationDefaults = typeof PAGINATION_DEFAULTS;
@@ -1,110 +1,14 @@
1
1
  /**
2
2
  * 分页结果类型定义
3
- */
4
-
5
- /**
6
- * 分页结果
7
- *
8
- * 包含分页数据和分页信息的完整结果
9
- *
10
- * @typeParam T - 数据项类型
11
- */
12
- export type PaginatedResult<T> = {
13
- /**
14
- * 数据项数组
15
- */
16
- items: T[];
17
-
18
- /**
19
- * 总记录数
20
- */
21
- total: number;
22
-
23
- /**
24
- * 当前页码
25
- */
26
- page: number;
27
-
28
- /**
29
- * 每页数量
30
- */
31
- pageSize: number;
32
-
33
- /**
34
- * 总页数
35
- */
36
- totalPages: number;
37
-
38
- /**
39
- * 是否有下一页
40
- */
41
- hasNextPage: boolean;
42
-
43
- /**
44
- * 是否有上一页
45
- */
46
- hasPreviousPage: boolean;
47
- };
48
-
49
- /**
50
- * Offset 风格分页结果
51
- *
52
- * 包含偏移量分页数据和分页信息
53
3
  *
54
- * @typeParam T - 数据项类型
4
+ * 类型从 zod schemas 推导导出
55
5
  */
56
- export type OffsetPaginatedResult<T> = {
57
- /**
58
- * 数据项数组
59
- */
60
- items: T[];
61
-
62
- /**
63
- * 总记录数
64
- */
65
- total: number;
66
-
67
- /**
68
- * 限制数量
69
- */
70
- limit: number;
71
-
72
- /**
73
- * 偏移量
74
- */
75
- offset: number;
76
-
77
- /**
78
- * 是否有更多数据
79
- */
80
- hasMore: boolean;
81
- };
82
-
83
- /**
84
- * 游标分页结果
85
- *
86
- * 包含游标分页数据和分页信息
87
- *
88
- * @typeParam T - 数据项类型
89
- */
90
- export type CursorPaginatedResult<T> = {
91
- /**
92
- * 数据项数组
93
- */
94
- items: T[];
95
-
96
- /**
97
- * 下一页游标
98
- */
99
- nextCursor: string | null;
100
-
101
- /**
102
- * 上一页游标
103
- */
104
- previousCursor: string | null;
105
6
 
106
- /**
107
- * 是否有更多数据
108
- */
109
- hasMore: boolean;
110
- };
7
+ export {
8
+ createPaginatedResultSchema,
9
+ createOffsetPaginatedResultSchema,
10
+ createCursorPaginatedResultSchema,
11
+ type PaginatedResult,
12
+ type OffsetPaginatedResult,
13
+ type CursorPaginatedResult,
14
+ } from '../schemas/result.schemas';
@@ -1,60 +1,19 @@
1
1
  /**
2
2
  * 排序类型定义
3
- */
4
-
5
- /**
6
- * 排序方向
7
- */
8
- export type SortOrder = 'asc' | 'desc';
9
-
10
- /**
11
- * 排序参数
12
- *
13
- * 单字段排序参数
14
- *
15
- * @typeParam T - 排序字段类型
16
- */
17
- export type SortParams<T extends string = string> = {
18
- /**
19
- * 排序字段
20
- */
21
- sortBy?: T;
22
-
23
- /**
24
- * 排序方向
25
- */
26
- sortOrder?: SortOrder;
27
- };
28
-
29
- /**
30
- * 多字段排序项
31
3
  *
32
- * 单个排序项定义
33
- *
34
- * @typeParam T - 排序字段类型
4
+ * 类型从 zod schemas 推导导出
35
5
  */
36
- export type SortItem<T extends string = string> = {
37
- /**
38
- * 排序字段
39
- */
40
- field: T;
41
-
42
- /**
43
- * 排序方向
44
- */
45
- order: SortOrder;
46
- };
47
6
 
48
- /**
49
- * 多字段排序参数
50
- *
51
- * 支持多个字段的排序
52
- *
53
- * @typeParam T - 排序字段类型
54
- */
55
- export type MultiSortParams<T extends string = string> = {
56
- /**
57
- * 排序项数组
58
- */
59
- sort?: SortItem<T>[];
60
- };
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';