@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,145 @@
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
+ //#endregion
27
+ //#region src/types/pagination.types.d.ts
28
+ declare const PAGINATION_DEFAULTS: {
29
+ readonly page: 1;
30
+ readonly pageSize: 20;
31
+ readonly maxPageSize: 100;
32
+ readonly minPageSize: 1;
33
+ };
34
+ //#endregion
35
+ //#region src/schemas/result.schemas.d.ts
36
+ declare function createPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
37
+ items: z.ZodArray<T>;
38
+ total: z.ZodNumber;
39
+ page: z.ZodNumber;
40
+ pageSize: z.ZodNumber;
41
+ totalPages: z.ZodNumber;
42
+ hasNextPage: z.ZodBoolean;
43
+ hasPreviousPage: z.ZodBoolean;
44
+ }, z.core.$strip>;
45
+ type PaginatedResult<T> = {
46
+ items: T[];
47
+ total: number;
48
+ page: number;
49
+ pageSize: number;
50
+ totalPages: number;
51
+ hasNextPage: boolean;
52
+ hasPreviousPage: boolean;
53
+ };
54
+ declare function createOffsetPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
55
+ items: z.ZodArray<T>;
56
+ total: z.ZodNumber;
57
+ limit: z.ZodNumber;
58
+ offset: z.ZodNumber;
59
+ hasMore: z.ZodBoolean;
60
+ }, z.core.$strip>;
61
+ type OffsetPaginatedResult<T> = {
62
+ items: T[];
63
+ total: number;
64
+ limit: number;
65
+ offset: number;
66
+ hasMore: boolean;
67
+ };
68
+ declare function createCursorPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
69
+ items: z.ZodArray<T>;
70
+ nextCursor: z.ZodNullable<z.ZodString>;
71
+ previousCursor: z.ZodNullable<z.ZodString>;
72
+ hasMore: z.ZodBoolean;
73
+ }, z.core.$strip>;
74
+ type CursorPaginatedResult<T> = {
75
+ items: T[];
76
+ nextCursor: string | null;
77
+ previousCursor: string | null;
78
+ hasMore: boolean;
79
+ };
80
+ //#endregion
81
+ //#region src/schemas/sort.schemas.d.ts
82
+ declare const SortOrderSchema: z.ZodEnum<{
83
+ asc: "asc";
84
+ desc: "desc";
85
+ }>;
86
+ type SortOrder = z.infer<typeof SortOrderSchema>;
87
+ type SortParams<T extends string = string> = {
88
+ sortBy?: T;
89
+ sortOrder?: SortOrder;
90
+ };
91
+ declare function createSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
92
+ 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>>;
93
+ sortOrder: z.ZodOptional<z.ZodEnum<{
94
+ asc: "asc";
95
+ desc: "desc";
96
+ }>>;
97
+ }, z.core.$strip>;
98
+ declare const SortParamsSchema: z.ZodObject<{
99
+ sortBy: z.ZodOptional<z.ZodString>;
100
+ sortOrder: z.ZodOptional<z.ZodEnum<{
101
+ asc: "asc";
102
+ desc: "desc";
103
+ }>>;
104
+ }, z.core.$strip>;
105
+ type SortItem<T extends string = string> = {
106
+ field: T;
107
+ order: SortOrder;
108
+ };
109
+ declare function createSortItemSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
110
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
111
+ order: z.ZodEnum<{
112
+ asc: "asc";
113
+ desc: "desc";
114
+ }>;
115
+ }, z.core.$strip>;
116
+ declare const SortItemSchema: z.ZodObject<{
117
+ field: z.ZodString;
118
+ order: z.ZodEnum<{
119
+ asc: "asc";
120
+ desc: "desc";
121
+ }>;
122
+ }, z.core.$strip>;
123
+ type MultiSortParams<T extends string = string> = {
124
+ sort?: SortItem<T>[];
125
+ };
126
+ declare function createMultiSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
127
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
128
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
129
+ order: z.ZodEnum<{
130
+ asc: "asc";
131
+ desc: "desc";
132
+ }>;
133
+ }, z.core.$strip>>>;
134
+ }, z.core.$strip>;
135
+ declare const MultiSortParamsSchema: z.ZodObject<{
136
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
137
+ field: z.ZodString;
138
+ order: z.ZodEnum<{
139
+ asc: "asc";
140
+ desc: "desc";
141
+ }>;
142
+ }, z.core.$strip>>>;
143
+ }, z.core.$strip>;
144
+ //#endregion
145
+ export { PaginationDefaults as C, PaginationParamsSchema as E, OffsetPaginationParamsSchema as S, PaginationParams as T, createPaginatedResultSchema as _, SortOrder as a, CursorPaginationParamsSchema as b, SortParamsSchema as c, createSortParamsSchema as d, CursorPaginatedResult as f, createOffsetPaginatedResultSchema as g, createCursorPaginatedResultSchema as h, SortItemSchema as i, createMultiSortParamsSchema as l, PaginatedResult as m, MultiSortParamsSchema as n, SortOrderSchema as o, OffsetPaginatedResult as p, SortItem as r, SortParams as s, MultiSortParams as t, createSortItemSchema as u, PAGINATION_DEFAULTS as v, PaginationDefaultsSchema as w, OffsetPaginationParams as x, CursorPaginationParams as y };
@@ -0,0 +1,145 @@
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
+ //#endregion
27
+ //#region src/types/pagination.types.d.ts
28
+ declare const PAGINATION_DEFAULTS: {
29
+ readonly page: 1;
30
+ readonly pageSize: 20;
31
+ readonly maxPageSize: 100;
32
+ readonly minPageSize: 1;
33
+ };
34
+ //#endregion
35
+ //#region src/schemas/result.schemas.d.ts
36
+ declare function createPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
37
+ items: z.ZodArray<T>;
38
+ total: z.ZodNumber;
39
+ page: z.ZodNumber;
40
+ pageSize: z.ZodNumber;
41
+ totalPages: z.ZodNumber;
42
+ hasNextPage: z.ZodBoolean;
43
+ hasPreviousPage: z.ZodBoolean;
44
+ }, z.core.$strip>;
45
+ type PaginatedResult<T> = {
46
+ items: T[];
47
+ total: number;
48
+ page: number;
49
+ pageSize: number;
50
+ totalPages: number;
51
+ hasNextPage: boolean;
52
+ hasPreviousPage: boolean;
53
+ };
54
+ declare function createOffsetPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
55
+ items: z.ZodArray<T>;
56
+ total: z.ZodNumber;
57
+ limit: z.ZodNumber;
58
+ offset: z.ZodNumber;
59
+ hasMore: z.ZodBoolean;
60
+ }, z.core.$strip>;
61
+ type OffsetPaginatedResult<T> = {
62
+ items: T[];
63
+ total: number;
64
+ limit: number;
65
+ offset: number;
66
+ hasMore: boolean;
67
+ };
68
+ declare function createCursorPaginatedResultSchema<T extends z.ZodTypeAny>(itemSchema: T): z.ZodObject<{
69
+ items: z.ZodArray<T>;
70
+ nextCursor: z.ZodNullable<z.ZodString>;
71
+ previousCursor: z.ZodNullable<z.ZodString>;
72
+ hasMore: z.ZodBoolean;
73
+ }, z.core.$strip>;
74
+ type CursorPaginatedResult<T> = {
75
+ items: T[];
76
+ nextCursor: string | null;
77
+ previousCursor: string | null;
78
+ hasMore: boolean;
79
+ };
80
+ //#endregion
81
+ //#region src/schemas/sort.schemas.d.ts
82
+ declare const SortOrderSchema: z.ZodEnum<{
83
+ asc: "asc";
84
+ desc: "desc";
85
+ }>;
86
+ type SortOrder = z.infer<typeof SortOrderSchema>;
87
+ type SortParams<T extends string = string> = {
88
+ sortBy?: T;
89
+ sortOrder?: SortOrder;
90
+ };
91
+ declare function createSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
92
+ 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>>;
93
+ sortOrder: z.ZodOptional<z.ZodEnum<{
94
+ asc: "asc";
95
+ desc: "desc";
96
+ }>>;
97
+ }, z.core.$strip>;
98
+ declare const SortParamsSchema: z.ZodObject<{
99
+ sortBy: z.ZodOptional<z.ZodString>;
100
+ sortOrder: z.ZodOptional<z.ZodEnum<{
101
+ asc: "asc";
102
+ desc: "desc";
103
+ }>>;
104
+ }, z.core.$strip>;
105
+ type SortItem<T extends string = string> = {
106
+ field: T;
107
+ order: SortOrder;
108
+ };
109
+ declare function createSortItemSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
110
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
111
+ order: z.ZodEnum<{
112
+ asc: "asc";
113
+ desc: "desc";
114
+ }>;
115
+ }, z.core.$strip>;
116
+ declare const SortItemSchema: z.ZodObject<{
117
+ field: z.ZodString;
118
+ order: z.ZodEnum<{
119
+ asc: "asc";
120
+ desc: "desc";
121
+ }>;
122
+ }, z.core.$strip>;
123
+ type MultiSortParams<T extends string = string> = {
124
+ sort?: SortItem<T>[];
125
+ };
126
+ declare function createMultiSortParamsSchema<T extends [string, ...string[]]>(fields: T): z.ZodObject<{
127
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
128
+ field: z.ZodEnum<{ [k_1 in T[number]]: k_1 } extends infer T_1 ? { [k in keyof T_1]: T_1[k] } : never>;
129
+ order: z.ZodEnum<{
130
+ asc: "asc";
131
+ desc: "desc";
132
+ }>;
133
+ }, z.core.$strip>>>;
134
+ }, z.core.$strip>;
135
+ declare const MultiSortParamsSchema: z.ZodObject<{
136
+ sort: z.ZodOptional<z.ZodArray<z.ZodObject<{
137
+ field: z.ZodString;
138
+ order: z.ZodEnum<{
139
+ asc: "asc";
140
+ desc: "desc";
141
+ }>;
142
+ }, z.core.$strip>>>;
143
+ }, z.core.$strip>;
144
+ //#endregion
145
+ export { PaginationDefaults as C, PaginationParamsSchema as E, OffsetPaginationParamsSchema as S, PaginationParams as T, createPaginatedResultSchema as _, SortOrder as a, CursorPaginationParamsSchema as b, SortParamsSchema as c, createSortParamsSchema as d, CursorPaginatedResult as f, createOffsetPaginatedResultSchema as g, createCursorPaginatedResultSchema as h, SortItemSchema as i, createMultiSortParamsSchema as l, PaginatedResult as m, MultiSortParamsSchema as n, SortOrderSchema as o, OffsetPaginatedResult as p, SortItem as r, SortParams as s, MultiSortParams as t, createSortItemSchema as u, PAGINATION_DEFAULTS as v, PaginationDefaultsSchema as w, OffsetPaginationParams as x, CursorPaginationParams as y };
package/dist/index.cjs CHANGED
@@ -1 +1,33 @@
1
- Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e={page:1,pageSize:20,maxPageSize:100,minPageSize:1};function t(t){return{page:Math.max(1,Math.floor(t?.page??e.page)),pageSize:Math.min(e.maxPageSize,Math.max(e.minPageSize,Math.floor(t?.pageSize??e.pageSize)))}}function n(t){return{limit:Math.min(e.maxPageSize,Math.max(e.minPageSize,Math.floor(t?.limit??e.pageSize))),offset:Math.max(0,Math.floor(t?.offset??0))}}function r(e,t){return(e-1)*t}function i(e,t){return t<=0?0:Math.ceil(e/t)}function a(e,t){return e<t}function o(e){return e>1}function s(e,t){let n=Math.max(1,t);return{page:Math.floor(e/n)+1,pageSize:n}}function c(e,t){let n=Math.max(1,e),r=Math.max(1,t);return{offset:(n-1)*r,limit:r}}function l(e,t,n,r){let s=i(t,r);return{items:e,total:t,page:n,pageSize:r,totalPages:s,hasNextPage:a(n,s),hasPreviousPage:o(n)}}function u(e){return typeof e==`object`&&!!e}function d(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1}function f(t){return typeof t==`number`&&Number.isInteger(t)&&t>=e.minPageSize&&t<=e.maxPageSize}function p(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0}function m(t){return typeof t==`number`&&Number.isInteger(t)&&t>=e.minPageSize&&t<=e.maxPageSize}function h(e){if(!u(e))return!1;let t=e.page,n=e.pageSize;return(t===void 0||d(t))&&(n===void 0||f(n))}function g(e){if(!u(e))return!1;let t=e.limit,n=e.offset;return(t===void 0||m(t))&&(n===void 0||p(n))}function _(e){return e!==void 0&&`mapper`in e}function v(e,t,n,r){let s=i(t,r);return{items:e,total:t,page:n,pageSize:r,totalPages:s,hasNextPage:a(n,s),hasPreviousPage:o(n)}}async function y(e,n,i){let{page:a,pageSize:o}=t(n),s={skip:r(a,o),take:o,where:i?.where,relations:i?.relations,select:i?.select,order:i?.order??{createdAt:`DESC`}},[c,l]=await e.findAndCount(s);return _(i)?v(await Promise.all(c.map(i.mapper)),l,a,o):v(c,l,a,o)}async function b(e,n,i){let{page:a,pageSize:o}=t(n),s=r(a,o);e.skip(s).take(o);let[c,l]=await e.getManyAndCount();return v(i?await Promise.all(c.map(i)):c,l,a,o)}function x(e,t){return e.createQueryBuilder(t??e.metadata.name.toLowerCase())}exports.PAGINATION_DEFAULTS=e,exports.calculateOffset=r,exports.calculateTotalPages=i,exports.createPaginatedResult=l,exports.createPaginationQueryBuilder=x,exports.hasNextPage=a,exports.hasPreviousPage=o,exports.isValidLimit=m,exports.isValidOffset=p,exports.isValidOffsetPagination=g,exports.isValidPage=d,exports.isValidPageSize=f,exports.isValidPagination=h,exports.normalizeOffsetPagination=n,exports.normalizePagination=t,exports.offsetToPage=s,exports.pageToOffset=c,exports.paginateWithQueryBuilder=b,exports.paginateWithRepository=y;
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_utils = require('./utils-DazsDMMu.cjs');
3
+
4
+ exports.CursorPaginationParamsSchema = require_utils.CursorPaginationParamsSchema;
5
+ exports.MultiSortParamsSchema = require_utils.MultiSortParamsSchema;
6
+ exports.OffsetPaginationParamsSchema = require_utils.OffsetPaginationParamsSchema;
7
+ exports.PAGINATION_DEFAULTS = require_utils.PAGINATION_DEFAULTS;
8
+ exports.PaginationDefaultsSchema = require_utils.PaginationDefaultsSchema;
9
+ exports.PaginationParamsSchema = require_utils.PaginationParamsSchema;
10
+ exports.SortItemSchema = require_utils.SortItemSchema;
11
+ exports.SortOrderSchema = require_utils.SortOrderSchema;
12
+ exports.SortParamsSchema = require_utils.SortParamsSchema;
13
+ exports.calculateOffset = require_utils.calculateOffset;
14
+ exports.calculateTotalPages = require_utils.calculateTotalPages;
15
+ exports.createCursorPaginatedResultSchema = require_utils.createCursorPaginatedResultSchema;
16
+ exports.createMultiSortParamsSchema = require_utils.createMultiSortParamsSchema;
17
+ exports.createOffsetPaginatedResultSchema = require_utils.createOffsetPaginatedResultSchema;
18
+ exports.createPaginatedResult = require_utils.createPaginatedResult;
19
+ exports.createPaginatedResultSchema = require_utils.createPaginatedResultSchema;
20
+ exports.createSortItemSchema = require_utils.createSortItemSchema;
21
+ exports.createSortParamsSchema = require_utils.createSortParamsSchema;
22
+ exports.hasNextPage = require_utils.hasNextPage;
23
+ exports.hasPreviousPage = require_utils.hasPreviousPage;
24
+ exports.isValidLimit = require_utils.isValidLimit;
25
+ exports.isValidOffset = require_utils.isValidOffset;
26
+ exports.isValidOffsetPagination = require_utils.isValidOffsetPagination;
27
+ exports.isValidPage = require_utils.isValidPage;
28
+ exports.isValidPageSize = require_utils.isValidPageSize;
29
+ exports.isValidPagination = require_utils.isValidPagination;
30
+ exports.normalizeOffsetPagination = require_utils.normalizeOffsetPagination;
31
+ exports.normalizePagination = require_utils.normalizePagination;
32
+ exports.offsetToPage = require_utils.offsetToPage;
33
+ exports.pageToOffset = require_utils.pageToOffset;
package/dist/index.d.cts CHANGED
@@ -1,64 +1,5 @@
1
- import { FindManyOptions, FindOptionsOrder, ObjectLiteral, Repository, SelectQueryBuilder } from "typeorm";
1
+ import { C as PaginationDefaults, E as PaginationParamsSchema, S as OffsetPaginationParamsSchema, T as PaginationParams, _ as createPaginatedResultSchema, a as SortOrder, b as CursorPaginationParamsSchema, c as SortParamsSchema, d as createSortParamsSchema, f as CursorPaginatedResult, g as createOffsetPaginatedResultSchema, h as createCursorPaginatedResultSchema, i as SortItemSchema, l as createMultiSortParamsSchema, m as PaginatedResult, n as MultiSortParamsSchema, o as SortOrderSchema, p as OffsetPaginatedResult, r as SortItem, s as SortParams, t as MultiSortParams, u as createSortItemSchema, v as PAGINATION_DEFAULTS, w as PaginationDefaultsSchema, x as OffsetPaginationParams, y as CursorPaginationParams } from "./index-CMiyhlfm.cjs";
2
2
 
3
- //#region src/types/pagination.types.d.ts
4
- type PaginationParams = {
5
- page?: number;
6
- pageSize?: number;
7
- };
8
- type OffsetPaginationParams = {
9
- limit?: number;
10
- offset?: number;
11
- };
12
- type CursorPaginationParams = {
13
- cursor?: string;
14
- limit?: number;
15
- };
16
- declare const PAGINATION_DEFAULTS: {
17
- readonly page: 1;
18
- readonly pageSize: 20;
19
- readonly maxPageSize: 100;
20
- readonly minPageSize: 1;
21
- };
22
- type PaginationDefaults = typeof PAGINATION_DEFAULTS;
23
- //#endregion
24
- //#region src/types/result.types.d.ts
25
- type PaginatedResult<T> = {
26
- items: T[];
27
- total: number;
28
- page: number;
29
- pageSize: number;
30
- totalPages: number;
31
- hasNextPage: boolean;
32
- hasPreviousPage: boolean;
33
- };
34
- type OffsetPaginatedResult<T> = {
35
- items: T[];
36
- total: number;
37
- limit: number;
38
- offset: number;
39
- hasMore: boolean;
40
- };
41
- type CursorPaginatedResult<T> = {
42
- items: T[];
43
- nextCursor: string | null;
44
- previousCursor: string | null;
45
- hasMore: boolean;
46
- };
47
- //#endregion
48
- //#region src/types/sort.types.d.ts
49
- type SortOrder = 'asc' | 'desc';
50
- type SortParams<T extends string = string> = {
51
- sortBy?: T;
52
- sortOrder?: SortOrder;
53
- };
54
- type SortItem<T extends string = string> = {
55
- field: T;
56
- order: SortOrder;
57
- };
58
- type MultiSortParams<T extends string = string> = {
59
- sort?: SortItem<T>[];
60
- };
61
- //#endregion
62
3
  //#region src/utils/pagination.util.d.ts
63
4
  type OffsetPaginationResult = {
64
5
  page: number;
@@ -94,24 +35,4 @@ declare function isValidLimit(limit: unknown): limit is number;
94
35
  declare function isValidPagination(params: unknown): params is PaginationValidationResult;
95
36
  declare function isValidOffsetPagination(params: unknown): params is OffsetPaginationValidationResult;
96
37
  //#endregion
97
- //#region src/adapters/typeorm.adapter.d.ts
98
- type EntityMapper<TEntity, TDto> = (entity: TEntity) => TDto | Promise<TDto>;
99
- type TypeOrmPaginateOptionsWithMapper<TEntity extends ObjectLiteral, TDto> = {
100
- mapper: EntityMapper<TEntity, TDto>;
101
- order?: FindOptionsOrder<TEntity>;
102
- where?: FindManyOptions<TEntity>['where'];
103
- relations?: FindManyOptions<TEntity>['relations'];
104
- select?: FindManyOptions<TEntity>['select'];
105
- };
106
- type TypeOrmPaginateOptionsNoMapper<TEntity extends ObjectLiteral> = {
107
- order?: FindOptionsOrder<TEntity>;
108
- where?: FindManyOptions<TEntity>['where'];
109
- relations?: FindManyOptions<TEntity>['relations'];
110
- select?: FindManyOptions<TEntity>['select'];
111
- };
112
- type TypeOrmPaginateOptions<TEntity extends ObjectLiteral, TDto = TEntity> = TypeOrmPaginateOptionsWithMapper<TEntity, TDto> | TypeOrmPaginateOptionsNoMapper<TEntity>;
113
- declare function paginateWithRepository<TEntity extends ObjectLiteral, TDto = TEntity>(repository: Repository<TEntity>, params: PaginationParams, options?: TypeOrmPaginateOptions<TEntity, TDto>): Promise<PaginatedResult<TEntity | TDto>>;
114
- declare function paginateWithQueryBuilder<TEntity extends ObjectLiteral, TDto = TEntity>(queryBuilder: SelectQueryBuilder<TEntity>, params: PaginationParams, mapper?: EntityMapper<TEntity, TDto>): Promise<PaginatedResult<TEntity | TDto>>;
115
- declare function createPaginationQueryBuilder<TEntity extends ObjectLiteral>(repository: Repository<TEntity>, alias?: string): SelectQueryBuilder<TEntity>;
116
- //#endregion
117
- export { type CursorPaginatedResult, type CursorPaginationParams, type EntityMapper, type MultiSortParams, type OffsetPaginatedResult, type OffsetPaginationParams, type OffsetPaginationResult, type OffsetPaginationValidationResult, PAGINATION_DEFAULTS, type PagePaginationResult, type PaginatedResult, type PaginationDefaults, type PaginationParams, type PaginationValidationResult, type SortItem, type SortOrder, type SortParams, type TypeOrmPaginateOptions, calculateOffset, calculateTotalPages, createPaginatedResult, createPaginationQueryBuilder, hasNextPage, hasPreviousPage, isValidLimit, isValidOffset, isValidOffsetPagination, isValidPage, isValidPageSize, isValidPagination, normalizeOffsetPagination, normalizePagination, offsetToPage, pageToOffset, paginateWithQueryBuilder, paginateWithRepository };
38
+ export { type CursorPaginatedResult, type CursorPaginationParams, CursorPaginationParamsSchema, type MultiSortParams, MultiSortParamsSchema, type OffsetPaginatedResult, type OffsetPaginationParams, OffsetPaginationParamsSchema, type OffsetPaginationResult, type OffsetPaginationValidationResult, PAGINATION_DEFAULTS, type PagePaginationResult, type PaginatedResult, type PaginationDefaults, PaginationDefaultsSchema, type PaginationParams, PaginationParamsSchema, type PaginationValidationResult, type SortItem, SortItemSchema, type SortOrder, SortOrderSchema, type SortParams, SortParamsSchema, calculateOffset, calculateTotalPages, createCursorPaginatedResultSchema, createMultiSortParamsSchema, createOffsetPaginatedResultSchema, createPaginatedResult, createPaginatedResultSchema, createSortItemSchema, createSortParamsSchema, hasNextPage, hasPreviousPage, isValidLimit, isValidOffset, isValidOffsetPagination, isValidPage, isValidPageSize, isValidPagination, normalizeOffsetPagination, normalizePagination, offsetToPage, pageToOffset };
package/dist/index.d.mts CHANGED
@@ -1,64 +1,5 @@
1
- import { FindManyOptions, FindOptionsOrder, ObjectLiteral, Repository, SelectQueryBuilder } from "typeorm";
1
+ import { C as PaginationDefaults, E as PaginationParamsSchema, S as OffsetPaginationParamsSchema, T as PaginationParams, _ as createPaginatedResultSchema, a as SortOrder, b as CursorPaginationParamsSchema, c as SortParamsSchema, d as createSortParamsSchema, f as CursorPaginatedResult, g as createOffsetPaginatedResultSchema, h as createCursorPaginatedResultSchema, i as SortItemSchema, l as createMultiSortParamsSchema, m as PaginatedResult, n as MultiSortParamsSchema, o as SortOrderSchema, p as OffsetPaginatedResult, r as SortItem, s as SortParams, t as MultiSortParams, u as createSortItemSchema, v as PAGINATION_DEFAULTS, w as PaginationDefaultsSchema, x as OffsetPaginationParams, y as CursorPaginationParams } from "./index-C8FaNzej.mjs";
2
2
 
3
- //#region src/types/pagination.types.d.ts
4
- type PaginationParams = {
5
- page?: number;
6
- pageSize?: number;
7
- };
8
- type OffsetPaginationParams = {
9
- limit?: number;
10
- offset?: number;
11
- };
12
- type CursorPaginationParams = {
13
- cursor?: string;
14
- limit?: number;
15
- };
16
- declare const PAGINATION_DEFAULTS: {
17
- readonly page: 1;
18
- readonly pageSize: 20;
19
- readonly maxPageSize: 100;
20
- readonly minPageSize: 1;
21
- };
22
- type PaginationDefaults = typeof PAGINATION_DEFAULTS;
23
- //#endregion
24
- //#region src/types/result.types.d.ts
25
- type PaginatedResult<T> = {
26
- items: T[];
27
- total: number;
28
- page: number;
29
- pageSize: number;
30
- totalPages: number;
31
- hasNextPage: boolean;
32
- hasPreviousPage: boolean;
33
- };
34
- type OffsetPaginatedResult<T> = {
35
- items: T[];
36
- total: number;
37
- limit: number;
38
- offset: number;
39
- hasMore: boolean;
40
- };
41
- type CursorPaginatedResult<T> = {
42
- items: T[];
43
- nextCursor: string | null;
44
- previousCursor: string | null;
45
- hasMore: boolean;
46
- };
47
- //#endregion
48
- //#region src/types/sort.types.d.ts
49
- type SortOrder = 'asc' | 'desc';
50
- type SortParams<T extends string = string> = {
51
- sortBy?: T;
52
- sortOrder?: SortOrder;
53
- };
54
- type SortItem<T extends string = string> = {
55
- field: T;
56
- order: SortOrder;
57
- };
58
- type MultiSortParams<T extends string = string> = {
59
- sort?: SortItem<T>[];
60
- };
61
- //#endregion
62
3
  //#region src/utils/pagination.util.d.ts
63
4
  type OffsetPaginationResult = {
64
5
  page: number;
@@ -94,24 +35,4 @@ declare function isValidLimit(limit: unknown): limit is number;
94
35
  declare function isValidPagination(params: unknown): params is PaginationValidationResult;
95
36
  declare function isValidOffsetPagination(params: unknown): params is OffsetPaginationValidationResult;
96
37
  //#endregion
97
- //#region src/adapters/typeorm.adapter.d.ts
98
- type EntityMapper<TEntity, TDto> = (entity: TEntity) => TDto | Promise<TDto>;
99
- type TypeOrmPaginateOptionsWithMapper<TEntity extends ObjectLiteral, TDto> = {
100
- mapper: EntityMapper<TEntity, TDto>;
101
- order?: FindOptionsOrder<TEntity>;
102
- where?: FindManyOptions<TEntity>['where'];
103
- relations?: FindManyOptions<TEntity>['relations'];
104
- select?: FindManyOptions<TEntity>['select'];
105
- };
106
- type TypeOrmPaginateOptionsNoMapper<TEntity extends ObjectLiteral> = {
107
- order?: FindOptionsOrder<TEntity>;
108
- where?: FindManyOptions<TEntity>['where'];
109
- relations?: FindManyOptions<TEntity>['relations'];
110
- select?: FindManyOptions<TEntity>['select'];
111
- };
112
- type TypeOrmPaginateOptions<TEntity extends ObjectLiteral, TDto = TEntity> = TypeOrmPaginateOptionsWithMapper<TEntity, TDto> | TypeOrmPaginateOptionsNoMapper<TEntity>;
113
- declare function paginateWithRepository<TEntity extends ObjectLiteral, TDto = TEntity>(repository: Repository<TEntity>, params: PaginationParams, options?: TypeOrmPaginateOptions<TEntity, TDto>): Promise<PaginatedResult<TEntity | TDto>>;
114
- declare function paginateWithQueryBuilder<TEntity extends ObjectLiteral, TDto = TEntity>(queryBuilder: SelectQueryBuilder<TEntity>, params: PaginationParams, mapper?: EntityMapper<TEntity, TDto>): Promise<PaginatedResult<TEntity | TDto>>;
115
- declare function createPaginationQueryBuilder<TEntity extends ObjectLiteral>(repository: Repository<TEntity>, alias?: string): SelectQueryBuilder<TEntity>;
116
- //#endregion
117
- export { type CursorPaginatedResult, type CursorPaginationParams, type EntityMapper, type MultiSortParams, type OffsetPaginatedResult, type OffsetPaginationParams, type OffsetPaginationResult, type OffsetPaginationValidationResult, PAGINATION_DEFAULTS, type PagePaginationResult, type PaginatedResult, type PaginationDefaults, type PaginationParams, type PaginationValidationResult, type SortItem, type SortOrder, type SortParams, type TypeOrmPaginateOptions, calculateOffset, calculateTotalPages, createPaginatedResult, createPaginationQueryBuilder, hasNextPage, hasPreviousPage, isValidLimit, isValidOffset, isValidOffsetPagination, isValidPage, isValidPageSize, isValidPagination, normalizeOffsetPagination, normalizePagination, offsetToPage, pageToOffset, paginateWithQueryBuilder, paginateWithRepository };
38
+ export { type CursorPaginatedResult, type CursorPaginationParams, CursorPaginationParamsSchema, type MultiSortParams, MultiSortParamsSchema, type OffsetPaginatedResult, type OffsetPaginationParams, OffsetPaginationParamsSchema, type OffsetPaginationResult, type OffsetPaginationValidationResult, PAGINATION_DEFAULTS, type PagePaginationResult, type PaginatedResult, type PaginationDefaults, PaginationDefaultsSchema, type PaginationParams, PaginationParamsSchema, type PaginationValidationResult, type SortItem, SortItemSchema, type SortOrder, SortOrderSchema, type SortParams, SortParamsSchema, calculateOffset, calculateTotalPages, createCursorPaginatedResultSchema, createMultiSortParamsSchema, createOffsetPaginatedResultSchema, createPaginatedResult, createPaginatedResultSchema, createSortItemSchema, createSortParamsSchema, hasNextPage, hasPreviousPage, isValidLimit, isValidOffset, isValidOffsetPagination, isValidPage, isValidPageSize, isValidPagination, normalizeOffsetPagination, normalizePagination, offsetToPage, pageToOffset };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- const e={page:1,pageSize:20,maxPageSize:100,minPageSize:1};function t(t){return{page:Math.max(1,Math.floor(t?.page??e.page)),pageSize:Math.min(e.maxPageSize,Math.max(e.minPageSize,Math.floor(t?.pageSize??e.pageSize)))}}function n(t){return{limit:Math.min(e.maxPageSize,Math.max(e.minPageSize,Math.floor(t?.limit??e.pageSize))),offset:Math.max(0,Math.floor(t?.offset??0))}}function r(e,t){return(e-1)*t}function i(e,t){return t<=0?0:Math.ceil(e/t)}function a(e,t){return e<t}function o(e){return e>1}function s(e,t){let n=Math.max(1,t);return{page:Math.floor(e/n)+1,pageSize:n}}function c(e,t){let n=Math.max(1,e),r=Math.max(1,t);return{offset:(n-1)*r,limit:r}}function l(e,t,n,r){let s=i(t,r);return{items:e,total:t,page:n,pageSize:r,totalPages:s,hasNextPage:a(n,s),hasPreviousPage:o(n)}}function u(e){return typeof e==`object`&&!!e}function d(e){return typeof e==`number`&&Number.isInteger(e)&&e>=1}function f(t){return typeof t==`number`&&Number.isInteger(t)&&t>=e.minPageSize&&t<=e.maxPageSize}function p(e){return typeof e==`number`&&Number.isInteger(e)&&e>=0}function m(t){return typeof t==`number`&&Number.isInteger(t)&&t>=e.minPageSize&&t<=e.maxPageSize}function h(e){if(!u(e))return!1;let t=e.page,n=e.pageSize;return(t===void 0||d(t))&&(n===void 0||f(n))}function g(e){if(!u(e))return!1;let t=e.limit,n=e.offset;return(t===void 0||m(t))&&(n===void 0||p(n))}function _(e){return e!==void 0&&`mapper`in e}function v(e,t,n,r){let s=i(t,r);return{items:e,total:t,page:n,pageSize:r,totalPages:s,hasNextPage:a(n,s),hasPreviousPage:o(n)}}async function y(e,n,i){let{page:a,pageSize:o}=t(n),s={skip:r(a,o),take:o,where:i?.where,relations:i?.relations,select:i?.select,order:i?.order??{createdAt:`DESC`}},[c,l]=await e.findAndCount(s);return _(i)?v(await Promise.all(c.map(i.mapper)),l,a,o):v(c,l,a,o)}async function b(e,n,i){let{page:a,pageSize:o}=t(n),s=r(a,o);e.skip(s).take(o);let[c,l]=await e.getManyAndCount();return v(i?await Promise.all(c.map(i)):c,l,a,o)}function x(e,t){return e.createQueryBuilder(t??e.metadata.name.toLowerCase())}export{e as PAGINATION_DEFAULTS,r as calculateOffset,i as calculateTotalPages,l as createPaginatedResult,x as createPaginationQueryBuilder,a as hasNextPage,o as hasPreviousPage,m as isValidLimit,p as isValidOffset,g as isValidOffsetPagination,d as isValidPage,f as isValidPageSize,h as isValidPagination,n as normalizeOffsetPagination,t as normalizePagination,s as offsetToPage,c as pageToOffset,b as paginateWithQueryBuilder,y as paginateWithRepository};
1
+ import{A as e,C as t,D as n,E as r,O as i,S as a,T as o,_ as s,a as c,b as l,c as u,d,f,g as p,h as m,i as h,k as g,l as _,m as v,n as y,o as b,p as x,r as S,s as C,t as w,u as T,v as E,w as D,x as O,y as k}from"./utils-CV6Ovku6.mjs";export{n as CursorPaginationParamsSchema,p as MultiSortParamsSchema,i as OffsetPaginationParamsSchema,r as PAGINATION_DEFAULTS,g as PaginationDefaultsSchema,e as PaginationParamsSchema,s as SortItemSchema,E as SortOrderSchema,k as SortParamsSchema,C as calculateOffset,u as calculateTotalPages,t as createCursorPaginatedResultSchema,l as createMultiSortParamsSchema,D as createOffsetPaginatedResultSchema,_ as createPaginatedResult,o as createPaginatedResultSchema,O as createSortItemSchema,a as createSortParamsSchema,T as hasNextPage,d as hasPreviousPage,w as isValidLimit,y as isValidOffset,S as isValidOffsetPagination,h as isValidPage,c as isValidPageSize,b as isValidPagination,f as normalizeOffsetPagination,x as normalizePagination,v as offsetToPage,m as pageToOffset};
@@ -0,0 +1,129 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_utils = require('./utils-DazsDMMu.cjs');
3
+
4
+ //#region src/adapters/typeorm/adapter.ts
5
+ /**
6
+ * 类型守卫:检查选项是否包含映射器
7
+ *
8
+ * @typeParam TEntity - 实体类型
9
+ * @typeParam TDto - DTO 类型
10
+ * @param options - 查询选项
11
+ * @returns 是否包含映射器
12
+ */
13
+ function hasMapper(options) {
14
+ return options !== void 0 && "mapper" in options;
15
+ }
16
+ /**
17
+ * 构建分页结果
18
+ *
19
+ * 内部辅助函数,构建分页结果对象
20
+ *
21
+ * @typeParam TDto - DTO 类型
22
+ * @param items - 数据项数组
23
+ * @param total - 总数
24
+ * @param page - 当前页
25
+ * @param pageSize - 每页大小
26
+ * @returns 分页结果
27
+ */
28
+ function buildPaginatedResult(items, total, page, pageSize) {
29
+ /**
30
+ * 计算得到的总页数
31
+ */
32
+ const totalPages = require_utils.calculateTotalPages(total, pageSize);
33
+ return {
34
+ items,
35
+ total,
36
+ page,
37
+ pageSize,
38
+ totalPages,
39
+ hasNextPage: require_utils.hasNextPage(page, totalPages),
40
+ hasPreviousPage: require_utils.hasPreviousPage(page)
41
+ };
42
+ }
43
+ /**
44
+ * 使用 Repository 进行分页查询
45
+ *
46
+ * 通过 TypeORM Repository 进行分页查询,支持实体到 DTO 的映射
47
+ *
48
+ * 当提供 mapper 时返回映射后的 DTO,否则返回原始实体
49
+ *
50
+ * @typeParam TEntity - 实体类型
51
+ * @typeParam TDto - DTO 类型
52
+ * @param repository - TypeORM 仓库
53
+ * @param params - 分页参数
54
+ * @param options - 查询选项
55
+ * @returns 分页结果
56
+ */
57
+ async function paginateWithRepository(repository, params, options) {
58
+ /**
59
+ * 规范化后的分页参数
60
+ */
61
+ const { page, pageSize } = require_utils.normalizePagination(params);
62
+ /**
63
+ * TypeORM 查询选项配置
64
+ */
65
+ const findOptions = {
66
+ skip: require_utils.calculateOffset(page, pageSize),
67
+ take: pageSize,
68
+ where: options?.where,
69
+ relations: options?.relations,
70
+ select: options?.select,
71
+ order: options?.order ?? { createdAt: "DESC" }
72
+ };
73
+ /**
74
+ * 查询结果:实体数组和总数
75
+ */
76
+ const [entities, total] = await repository.findAndCount(findOptions);
77
+ if (hasMapper(options)) return buildPaginatedResult(await Promise.all(entities.map(options.mapper)), total, page, pageSize);
78
+ return buildPaginatedResult(entities, total, page, pageSize);
79
+ }
80
+ /**
81
+ * 使用 QueryBuilder 进行分页查询
82
+ *
83
+ * 通过 TypeORM QueryBuilder 进行分页查询,支持实体到 DTO 的映射
84
+ *
85
+ * 当提供 mapper 时返回映射后的 DTO,否则返回原始实体
86
+ *
87
+ * @typeParam TEntity - 实体类型
88
+ * @typeParam TDto - DTO 类型
89
+ * @param queryBuilder - TypeORM QueryBuilder
90
+ * @param params - 分页参数
91
+ * @param mapper - 实体到 DTO 的映射函数(可选)
92
+ * @returns 分页结果
93
+ */
94
+ async function paginateWithQueryBuilder(queryBuilder, params, mapper) {
95
+ /**
96
+ * 规范化后的分页参数
97
+ */
98
+ const { page, pageSize } = require_utils.normalizePagination(params);
99
+ /**
100
+ * 计算得到的偏移量
101
+ */
102
+ const offset = require_utils.calculateOffset(page, pageSize);
103
+ queryBuilder.skip(offset).take(pageSize);
104
+ /**
105
+ * 查询结果:实体数组和总数
106
+ */
107
+ const [entities, total] = await queryBuilder.getManyAndCount();
108
+ if (mapper) return buildPaginatedResult(await Promise.all(entities.map(mapper)), total, page, pageSize);
109
+ return buildPaginatedResult(entities, total, page, pageSize);
110
+ }
111
+ /**
112
+ * 创建分页查询构建器
113
+ *
114
+ * 创建一个用于分页查询的 TypeORM QueryBuilder
115
+ *
116
+ * @typeParam TEntity - 实体类型
117
+ * @param repository - TypeORM 仓库
118
+ * @param alias - 查询别名
119
+ * @returns QueryBuilder
120
+ */
121
+ function createPaginationQueryBuilder(repository, alias) {
122
+ return repository.createQueryBuilder(alias ?? repository.metadata.name.toLowerCase());
123
+ }
124
+
125
+ //#endregion
126
+ exports.createPaginationQueryBuilder = createPaginationQueryBuilder;
127
+ exports.paginateWithQueryBuilder = paginateWithQueryBuilder;
128
+ exports.paginateWithRepository = paginateWithRepository;
129
+ //# sourceMappingURL=typeorm.cjs.map