@lyxa.ai/core 1.4.335 → 1.4.336
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.
- package/dist/libraries/event/events/mongo-stream-changes-batch-process-shops-event.d.ts +2 -2
- package/dist/libraries/event/events/punch-marketing/sync-user-shop-punch-marketing-history-event.d.ts +2 -2
- package/dist/libraries/event/events/sync-order-again-sections-for-shop-event.d.ts +2 -2
- package/dist/libraries/socket/events/chatroom-message-send.socket.event.d.ts +25 -25
- package/dist/libraries/socket/events/order-actions.socket.event.d.ts +24 -24
- package/dist/libraries/socket/events/rider-location-update.socket.event.d.ts +4 -4
- package/dist/libraries/socket/events/ticket-actions.socket.event.d.ts +12 -12
- package/dist/libraries/socket/events/ticket-assign.socket.event.d.ts +4 -4
- package/dist/libraries/trpc/middlewares/auth.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/createRoleProtectedProcedure.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/phone-verified.d.ts +2 -2
- package/dist/libraries/trpc/middlewares/publicUserDecoder.d.ts +2 -2
- package/dist/types/README.md +1 -1
- package/dist/types/package.json +1 -1
- package/dist/types/utilities/validation/common-validation.d.ts +66 -66
- package/dist/types/utilities/validation/validation-for-frontend.d.ts +2 -2
- package/dist/utilities/pagination.d.ts +5 -5
- package/dist/utilities/pagination.js +3 -3
- package/dist/utilities/pagination.js.map +1 -1
- package/dist/utilities/validation/common-validation.d.ts +70 -70
- package/dist/utilities/validation/validation-for-frontend.d.ts +2 -2
- package/package.json +1 -1
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function createAuthenticatedProcedure(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
+
requestId: string | undefined;
|
|
9
|
+
entity: import("../context").EntityContext | undefined;
|
|
8
10
|
req: import("http").IncomingMessage;
|
|
9
11
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
|
-
entity: import("../context").EntityContext | undefined;
|
|
11
|
-
requestId: string | undefined;
|
|
12
12
|
tokenType: TokenType | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
|
@@ -4,10 +4,10 @@ interface RoleProtectedOptions {
|
|
|
4
4
|
allowedRoles: string[];
|
|
5
5
|
}
|
|
6
6
|
export declare function createRoleProtectedProcedure(options: RoleProtectedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
7
|
+
requestId: string | undefined;
|
|
8
|
+
entity: import("../context").EntityContext | undefined;
|
|
7
9
|
req: import("http").IncomingMessage;
|
|
8
10
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
9
|
-
entity: import("../context").EntityContext | undefined;
|
|
10
|
-
requestId: string | undefined;
|
|
11
11
|
tokenType: import("../../auth").TokenType | undefined;
|
|
12
12
|
usedRefreshToken: boolean | undefined;
|
|
13
13
|
tokenRenewed: boolean | undefined;
|
|
@@ -3,10 +3,10 @@ interface PhoneVerifiedOptions {
|
|
|
3
3
|
entityTypes: AuthEntityType[];
|
|
4
4
|
}
|
|
5
5
|
export declare function createPhoneVerifiedProcedure(options: PhoneVerifiedOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
6
|
+
requestId: string | undefined;
|
|
7
|
+
entity: import("../context").EntityContext | undefined;
|
|
6
8
|
req: import("http").IncomingMessage;
|
|
7
9
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
8
|
-
entity: import("../context").EntityContext | undefined;
|
|
9
|
-
requestId: string | undefined;
|
|
10
10
|
tokenType: import("../../auth").TokenType | undefined;
|
|
11
11
|
usedRefreshToken: boolean | undefined;
|
|
12
12
|
tokenRenewed: boolean | undefined;
|
|
@@ -5,10 +5,10 @@ interface AuthOptions {
|
|
|
5
5
|
autoRefresh?: boolean;
|
|
6
6
|
}
|
|
7
7
|
export declare function publicUserDecoder(options: AuthOptions): import("@trpc/server").TRPCProcedureBuilder<import("../context").LyxaHTTPContext, object, {
|
|
8
|
+
requestId: string | undefined;
|
|
9
|
+
entity: import("../context").EntityContext | undefined;
|
|
8
10
|
req: import("http").IncomingMessage;
|
|
9
11
|
res: import("http").ServerResponse<import("http").IncomingMessage>;
|
|
10
|
-
entity: import("../context").EntityContext | undefined;
|
|
11
|
-
requestId: string | undefined;
|
|
12
12
|
tokenType: TokenType | undefined;
|
|
13
13
|
usedRefreshToken: boolean | undefined;
|
|
14
14
|
tokenRenewed: boolean | undefined;
|
package/dist/types/README.md
CHANGED
package/dist/types/package.json
CHANGED
|
@@ -22,32 +22,32 @@ export declare const FilterSchema: z.ZodOptional<z.ZodObject<{
|
|
|
22
22
|
size: number;
|
|
23
23
|
page: number;
|
|
24
24
|
sort?: Record<string, 1 | -1> | undefined;
|
|
25
|
-
query?: Record<string, any> | undefined;
|
|
26
|
-
select?: Record<string, 0 | 1> | undefined;
|
|
27
|
-
populate?: any;
|
|
28
25
|
search?: {
|
|
29
26
|
searchKey: string;
|
|
30
27
|
searchFields?: string[] | undefined;
|
|
31
28
|
} | undefined;
|
|
32
|
-
}, {
|
|
33
|
-
sort?: Record<string, 1 | -1> | undefined;
|
|
34
|
-
size?: number | undefined;
|
|
35
|
-
page?: number | undefined;
|
|
36
|
-
query?: Record<string, any> | undefined;
|
|
37
29
|
select?: Record<string, 0 | 1> | undefined;
|
|
38
30
|
populate?: any;
|
|
31
|
+
query?: Record<string, any> | undefined;
|
|
32
|
+
}, {
|
|
33
|
+
sort?: Record<string, 1 | -1> | undefined;
|
|
39
34
|
search?: {
|
|
40
35
|
searchKey: string;
|
|
41
36
|
searchFields?: string[] | undefined;
|
|
42
37
|
} | undefined;
|
|
38
|
+
select?: Record<string, 0 | 1> | undefined;
|
|
39
|
+
populate?: any;
|
|
40
|
+
size?: number | undefined;
|
|
41
|
+
page?: number | undefined;
|
|
42
|
+
query?: Record<string, any> | undefined;
|
|
43
43
|
}>>;
|
|
44
44
|
export type FilterDTO = z.infer<typeof FilterSchema>;
|
|
45
45
|
export declare const StringSchema: z.ZodString;
|
|
46
46
|
export declare const AddressSchema: z.ZodObject<{
|
|
47
47
|
address: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
48
|
-
description: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
49
|
-
city: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
50
|
-
state: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
48
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
49
|
+
city: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
50
|
+
state: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
51
51
|
country: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
52
52
|
location: z.ZodObject<{
|
|
53
53
|
type: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
@@ -92,9 +92,9 @@ export declare const AddressSchema: z.ZodObject<{
|
|
|
92
92
|
export type AddressDTO = DTO<typeof AddressSchema>;
|
|
93
93
|
export declare const UserAddressSchema: z.ZodObject<{
|
|
94
94
|
address: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
95
|
-
description: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
96
|
-
city: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
97
|
-
state: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
95
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
96
|
+
city: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
97
|
+
state: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
98
98
|
country: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
99
99
|
location: z.ZodObject<{
|
|
100
100
|
type: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
@@ -113,12 +113,9 @@ export declare const UserAddressSchema: z.ZodObject<{
|
|
|
113
113
|
addressLabel: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
114
114
|
apartment: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
115
115
|
buildingName: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
116
|
-
deliveryOption: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
117
|
-
instructions: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
116
|
+
deliveryOption: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
117
|
+
instructions: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
118
118
|
}, "strip", z.ZodTypeAny, {
|
|
119
|
-
addressLabel: string;
|
|
120
|
-
apartment: string;
|
|
121
|
-
buildingName: string;
|
|
122
119
|
address: string;
|
|
123
120
|
country: string;
|
|
124
121
|
location: {
|
|
@@ -127,16 +124,16 @@ export declare const UserAddressSchema: z.ZodObject<{
|
|
|
127
124
|
};
|
|
128
125
|
latitude: number;
|
|
129
126
|
longitude: number;
|
|
130
|
-
|
|
131
|
-
|
|
127
|
+
addressLabel: string;
|
|
128
|
+
apartment: string;
|
|
129
|
+
buildingName: string;
|
|
132
130
|
description?: string | undefined;
|
|
133
131
|
city?: string | undefined;
|
|
134
132
|
state?: string | undefined;
|
|
135
133
|
zone?: import("mongoose").Types.ObjectId | undefined;
|
|
134
|
+
deliveryOption?: string | undefined;
|
|
135
|
+
instructions?: string | undefined;
|
|
136
136
|
}, {
|
|
137
|
-
addressLabel: string;
|
|
138
|
-
apartment: string;
|
|
139
|
-
buildingName: string;
|
|
140
137
|
address: string;
|
|
141
138
|
country: string;
|
|
142
139
|
location: {
|
|
@@ -145,19 +142,22 @@ export declare const UserAddressSchema: z.ZodObject<{
|
|
|
145
142
|
};
|
|
146
143
|
latitude: number;
|
|
147
144
|
longitude: number;
|
|
148
|
-
|
|
149
|
-
|
|
145
|
+
addressLabel: string;
|
|
146
|
+
apartment: string;
|
|
147
|
+
buildingName: string;
|
|
150
148
|
description?: string | undefined;
|
|
151
149
|
city?: string | undefined;
|
|
152
150
|
state?: string | undefined;
|
|
153
151
|
zone?: string | import("mongoose").Types.ObjectId | undefined;
|
|
152
|
+
deliveryOption?: string | undefined;
|
|
153
|
+
instructions?: string | undefined;
|
|
154
154
|
}>;
|
|
155
155
|
export type UserAddressDTO = DTO<typeof UserAddressSchema>;
|
|
156
156
|
export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
157
157
|
address: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
158
|
-
description: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
159
|
-
city: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
160
|
-
state: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
158
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
159
|
+
city: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
160
|
+
state: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
161
161
|
country: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
162
162
|
location: z.ZodObject<{
|
|
163
163
|
type: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
@@ -176,15 +176,12 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
176
176
|
addressLabel: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
177
177
|
apartment: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
178
178
|
buildingName: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
179
|
-
deliveryOption: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
180
|
-
instructions: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
179
|
+
deliveryOption: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
180
|
+
instructions: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
181
181
|
} & {
|
|
182
182
|
_id: z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>;
|
|
183
183
|
}, "strip", z.ZodTypeAny, {
|
|
184
184
|
_id: import("mongoose").Types.ObjectId;
|
|
185
|
-
addressLabel: string;
|
|
186
|
-
apartment: string;
|
|
187
|
-
buildingName: string;
|
|
188
185
|
address: string;
|
|
189
186
|
country: string;
|
|
190
187
|
location: {
|
|
@@ -193,17 +190,17 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
193
190
|
};
|
|
194
191
|
latitude: number;
|
|
195
192
|
longitude: number;
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
addressLabel: string;
|
|
194
|
+
apartment: string;
|
|
195
|
+
buildingName: string;
|
|
198
196
|
description?: string | undefined;
|
|
199
197
|
city?: string | undefined;
|
|
200
198
|
state?: string | undefined;
|
|
201
199
|
zone?: import("mongoose").Types.ObjectId | undefined;
|
|
200
|
+
deliveryOption?: string | undefined;
|
|
201
|
+
instructions?: string | undefined;
|
|
202
202
|
}, {
|
|
203
203
|
_id: string | import("mongoose").Types.ObjectId;
|
|
204
|
-
addressLabel: string;
|
|
205
|
-
apartment: string;
|
|
206
|
-
buildingName: string;
|
|
207
204
|
address: string;
|
|
208
205
|
country: string;
|
|
209
206
|
location: {
|
|
@@ -212,19 +209,22 @@ export declare const RegularOrderAddressSchema: z.ZodObject<{
|
|
|
212
209
|
};
|
|
213
210
|
latitude: number;
|
|
214
211
|
longitude: number;
|
|
215
|
-
|
|
216
|
-
|
|
212
|
+
addressLabel: string;
|
|
213
|
+
apartment: string;
|
|
214
|
+
buildingName: string;
|
|
217
215
|
description?: string | undefined;
|
|
218
216
|
city?: string | undefined;
|
|
219
217
|
state?: string | undefined;
|
|
220
218
|
zone?: string | import("mongoose").Types.ObjectId | undefined;
|
|
219
|
+
deliveryOption?: string | undefined;
|
|
220
|
+
instructions?: string | undefined;
|
|
221
221
|
}>;
|
|
222
222
|
export type RegularOrderAddressDTO = DTO<typeof RegularOrderAddressSchema>;
|
|
223
223
|
export declare const CourierAddressSchema: z.ZodObject<{
|
|
224
224
|
address: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
225
|
-
description: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
226
|
-
city: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
227
|
-
state: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
225
|
+
description: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
226
|
+
city: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
227
|
+
state: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
228
228
|
country: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
229
229
|
location: z.ZodObject<{
|
|
230
230
|
type: z.ZodDefault<z.ZodNativeEnum<typeof GeoLocationType>>;
|
|
@@ -240,15 +240,14 @@ export declare const CourierAddressSchema: z.ZodObject<{
|
|
|
240
240
|
longitude: z.ZodNumber;
|
|
241
241
|
zone: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, import("mongoose").Types.ObjectId, string>, z.ZodType<import("mongoose").Types.ObjectId, z.ZodTypeDef, import("mongoose").Types.ObjectId>]>>;
|
|
242
242
|
addressLabel: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
243
|
-
deliveryOption: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
244
|
-
instructions: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
243
|
+
deliveryOption: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
244
|
+
instructions: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
245
245
|
} & {
|
|
246
246
|
name: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
247
247
|
phoneNumber: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
248
|
-
apartment: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
249
|
-
buildingName: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
248
|
+
apartment: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
249
|
+
buildingName: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
250
250
|
}, "strip", z.ZodTypeAny, {
|
|
251
|
-
addressLabel: string;
|
|
252
251
|
address: string;
|
|
253
252
|
country: string;
|
|
254
253
|
location: {
|
|
@@ -257,18 +256,18 @@ export declare const CourierAddressSchema: z.ZodObject<{
|
|
|
257
256
|
};
|
|
258
257
|
latitude: number;
|
|
259
258
|
longitude: number;
|
|
259
|
+
addressLabel: string;
|
|
260
260
|
name: string;
|
|
261
261
|
phoneNumber: string;
|
|
262
|
-
apartment?: string | undefined;
|
|
263
|
-
buildingName?: string | undefined;
|
|
264
|
-
deliveryOption?: string | undefined;
|
|
265
|
-
instructions?: string | undefined;
|
|
266
262
|
description?: string | undefined;
|
|
267
263
|
city?: string | undefined;
|
|
268
264
|
state?: string | undefined;
|
|
269
265
|
zone?: import("mongoose").Types.ObjectId | undefined;
|
|
266
|
+
apartment?: string | undefined;
|
|
267
|
+
buildingName?: string | undefined;
|
|
268
|
+
deliveryOption?: string | undefined;
|
|
269
|
+
instructions?: string | undefined;
|
|
270
270
|
}, {
|
|
271
|
-
addressLabel: string;
|
|
272
271
|
address: string;
|
|
273
272
|
country: string;
|
|
274
273
|
location: {
|
|
@@ -277,16 +276,17 @@ export declare const CourierAddressSchema: z.ZodObject<{
|
|
|
277
276
|
};
|
|
278
277
|
latitude: number;
|
|
279
278
|
longitude: number;
|
|
279
|
+
addressLabel: string;
|
|
280
280
|
name: string;
|
|
281
281
|
phoneNumber: string;
|
|
282
|
-
apartment?: string | undefined;
|
|
283
|
-
buildingName?: string | undefined;
|
|
284
|
-
deliveryOption?: string | undefined;
|
|
285
|
-
instructions?: string | undefined;
|
|
286
282
|
description?: string | undefined;
|
|
287
283
|
city?: string | undefined;
|
|
288
284
|
state?: string | undefined;
|
|
289
285
|
zone?: string | import("mongoose").Types.ObjectId | undefined;
|
|
286
|
+
apartment?: string | undefined;
|
|
287
|
+
buildingName?: string | undefined;
|
|
288
|
+
deliveryOption?: string | undefined;
|
|
289
|
+
instructions?: string | undefined;
|
|
290
290
|
}>;
|
|
291
291
|
export type CourierAddressDTO = DTO<typeof CourierAddressSchema>;
|
|
292
292
|
export declare const DurationSchema: z.ZodObject<{
|
|
@@ -510,7 +510,7 @@ export declare const WorkHourSettingSchema: z.ZodObject<{
|
|
|
510
510
|
export declare const LoginSchema: z.ZodObject<{
|
|
511
511
|
email: z.ZodEffects<z.ZodString, string, string>;
|
|
512
512
|
password: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
513
|
-
deviceId: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
513
|
+
deviceId: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
514
514
|
}, "strip", z.ZodTypeAny, {
|
|
515
515
|
email: string;
|
|
516
516
|
password: string;
|
|
@@ -803,13 +803,13 @@ export declare const GetOneQuerySchema: z.ZodObject<{
|
|
|
803
803
|
select: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<[z.ZodLiteral<0>, z.ZodLiteral<1>]>>>;
|
|
804
804
|
populate: z.ZodOptional<z.ZodUnion<[z.ZodType<any, z.ZodTypeDef, any>, z.ZodArray<z.ZodType<any, z.ZodTypeDef, any>, "many">]>>;
|
|
805
805
|
}, "strip", z.ZodTypeAny, {
|
|
806
|
-
query?: Record<string, any> | undefined;
|
|
807
806
|
select?: Record<string, 0 | 1> | undefined;
|
|
808
807
|
populate?: any;
|
|
809
|
-
}, {
|
|
810
808
|
query?: Record<string, any> | undefined;
|
|
809
|
+
}, {
|
|
811
810
|
select?: Record<string, 0 | 1> | undefined;
|
|
812
811
|
populate?: any;
|
|
812
|
+
query?: Record<string, any> | undefined;
|
|
813
813
|
}>;
|
|
814
814
|
export type GetOneQueryDTO = DTO<typeof GetOneQuerySchema>;
|
|
815
815
|
declare const ShareableLinkSchema: z.ZodObject<{
|
|
@@ -920,8 +920,8 @@ export declare const UpdateFcmTokenInputSchema: z.ZodObject<{
|
|
|
920
920
|
fcmToken: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
921
921
|
action: z.ZodNativeEnum<typeof ActionType>;
|
|
922
922
|
platform: z.ZodOptional<z.ZodNativeEnum<typeof AppPlatform>>;
|
|
923
|
-
appVersion: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
924
|
-
deviceId: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
923
|
+
appVersion: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
924
|
+
deviceId: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
925
925
|
}, "strip", z.ZodTypeAny, {
|
|
926
926
|
fcmToken: string;
|
|
927
927
|
action: ActionType;
|
|
@@ -949,9 +949,9 @@ export declare const AssignRiderSchema: z.ZodObject<{
|
|
|
949
949
|
export type AssignRiderDTO = DTO<typeof AssignRiderSchema>;
|
|
950
950
|
export declare const PaymentInformationSchema: z.ZodObject<{
|
|
951
951
|
cardType: z.ZodDefault<z.ZodNativeEnum<typeof CardType>>;
|
|
952
|
-
paymentIntentId: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
953
|
-
orderId: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
954
|
-
transactionId: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
952
|
+
paymentIntentId: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
953
|
+
orderId: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
954
|
+
transactionId: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
955
955
|
}, "strip", z.ZodTypeAny, {
|
|
956
956
|
cardType: CardType;
|
|
957
957
|
paymentIntentId?: string | undefined;
|
|
@@ -4,8 +4,8 @@ export declare const UserAddressFrontendSchema: z.ZodObject<{
|
|
|
4
4
|
addressLabel: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
5
5
|
apartment: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
6
6
|
buildingName: z.ZodString | z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>;
|
|
7
|
-
deliveryOption: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
8
|
-
instructions: z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string
|
|
7
|
+
deliveryOption: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
8
|
+
instructions: z.ZodOptional<z.ZodString> | z.ZodOptional<z.ZodEffects<z.ZodEffects<z.ZodString, string, string>, string, string>>;
|
|
9
9
|
}, "strip", z.ZodTypeAny, {
|
|
10
10
|
addressLabel: string;
|
|
11
11
|
apartment: string;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
-
import { FilterQuery, PopulateOptions, Model } from 'mongoose';
|
|
2
|
+
import { ClientSession, FilterQuery, PopulateOptions, Model } from 'mongoose';
|
|
3
3
|
import { AnyParamConstructor } from '@typegoose/typegoose/lib/types';
|
|
4
4
|
import { DocumentType, ReturnModelType } from '@typegoose/typegoose';
|
|
5
5
|
import { CustomPaginatedResponse, CustomPaginatorOptions } from './validation';
|
|
@@ -22,6 +22,7 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
22
22
|
}, z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodUnion<[z.ZodString, z.ZodNumber]>, z.ZodBoolean]>, z.ZodNull]>, z.ZodUndefined]>, "strip">>;
|
|
23
23
|
items: z.ZodArray<ItemType, "many">;
|
|
24
24
|
}, "strip", z.ZodTypeAny, {
|
|
25
|
+
items: ItemType["_output"][];
|
|
25
26
|
metadata: {
|
|
26
27
|
size: number;
|
|
27
28
|
page: number;
|
|
@@ -30,8 +31,8 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
30
31
|
} & {
|
|
31
32
|
[k: string]: string | number | boolean | null | undefined;
|
|
32
33
|
};
|
|
33
|
-
items: ItemType["_output"][];
|
|
34
34
|
}, {
|
|
35
|
+
items: ItemType["_input"][];
|
|
35
36
|
metadata: {
|
|
36
37
|
size: number;
|
|
37
38
|
page: number;
|
|
@@ -40,7 +41,6 @@ export declare function createPaginatedSchema<ItemType extends z.ZodTypeAny>(ite
|
|
|
40
41
|
} & {
|
|
41
42
|
[k: string]: string | number | boolean | null | undefined;
|
|
42
43
|
};
|
|
43
|
-
items: ItemType["_input"][];
|
|
44
44
|
}>;
|
|
45
45
|
export interface RawPaginatedResult<T extends AnyParamConstructor<any>> {
|
|
46
46
|
metadata: {
|
|
@@ -62,6 +62,7 @@ export interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {
|
|
|
62
62
|
}
|
|
63
63
|
export declare function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(model: ReturnModelType<T>): (options: PaginatorOptions<T>) => Promise<RawPaginatedResult<T>>;
|
|
64
64
|
export declare function createPaginatorObject<T extends AnyParamConstructor<any>>(model: ReturnModelType<T>, itemSchema: z.ZodTypeAny, transformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>): (options: PaginatorOptions<T>) => Promise<{
|
|
65
|
+
items: any[];
|
|
65
66
|
metadata: {
|
|
66
67
|
size: number;
|
|
67
68
|
page: number;
|
|
@@ -70,9 +71,8 @@ export declare function createPaginatorObject<T extends AnyParamConstructor<any>
|
|
|
70
71
|
} & {
|
|
71
72
|
[k: string]: string | number | boolean | null | undefined;
|
|
72
73
|
};
|
|
73
|
-
items: any[];
|
|
74
74
|
}>;
|
|
75
|
-
export declare function paginateAggregation(model: any, pipeline: any[], page?: number, size?: number, sort?: any, populateOptions?: any): Promise<{
|
|
75
|
+
export declare function paginateAggregation(model: any, pipeline: any[], page?: number, size?: number, sort?: any, populateOptions?: any, session?: ClientSession | null): Promise<{
|
|
76
76
|
metadata: {
|
|
77
77
|
page: number;
|
|
78
78
|
size: number;
|
|
@@ -62,12 +62,12 @@ function createPaginatorObject(model, itemSchema, transformFn) {
|
|
|
62
62
|
return PaginatedSchema.parse(paginatedResult);
|
|
63
63
|
};
|
|
64
64
|
}
|
|
65
|
-
async function paginateAggregation(model, pipeline, page = 1, size = 10, sort, populateOptions) {
|
|
65
|
+
async function paginateAggregation(model, pipeline, page = 1, size = 10, sort, populateOptions, session) {
|
|
66
66
|
const skip = (page - 1) * size;
|
|
67
67
|
const limit = size;
|
|
68
68
|
const pipelineWithCount = [...pipeline];
|
|
69
69
|
pipelineWithCount.push({ $count: 'totalCount' });
|
|
70
|
-
const totalCountResult = await model.aggregate(pipelineWithCount).exec();
|
|
70
|
+
const totalCountResult = await model.aggregate(pipelineWithCount).session(session ?? null).exec();
|
|
71
71
|
const totalElements = totalCountResult?.[0]?.totalCount || 0;
|
|
72
72
|
const totalPages = Math.ceil(totalElements / size);
|
|
73
73
|
const paginatedPipeline = [...pipeline];
|
|
@@ -76,7 +76,7 @@ async function paginateAggregation(model, pipeline, page = 1, size = 10, sort, p
|
|
|
76
76
|
}
|
|
77
77
|
paginatedPipeline.push({ $skip: skip });
|
|
78
78
|
paginatedPipeline.push({ $limit: limit });
|
|
79
|
-
const data = await model.aggregate(paginatedPipeline).exec();
|
|
79
|
+
const data = await model.aggregate(paginatedPipeline).session(session ?? null).exec();
|
|
80
80
|
const populatedData = populateOptions ? await model.populate(data, populateOptions) : data;
|
|
81
81
|
return {
|
|
82
82
|
metadata: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pagination.js","sourceRoot":"/","sources":["utilities/pagination.ts"],"names":[],"mappings":";;AASA,sDAYC;AAuED,4EAWC;AASD,sDAmBC;AACD,kDAiDC;AAKD,wCA4CC;AAtOD,6BAAwB;AASxB,SAAgB,qBAAqB,CAAgC,UAAoB;IACxF,OAAO,OAAC,CAAC,MAAM,CAAC;QACf,QAAQ,EAAE,OAAC;aACT,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;YACzB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;SACtB,CAAC;aACD,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACp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AAI;YACJ,IAAI;YACJ,aAAa;YACb,UAAU;SACV;KACD,CAAC;AACH,CAAC","sourcesContent":["import { z } from 'zod';\nimport { FilterQuery, PopulateOptions, Model } from 'mongoose';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { DocumentType, ReturnModelType } from '@typegoose/typegoose';\nimport { CustomPaginatedResponse, CustomPaginatorOptions } from './validation';\n\n/**\n * A helper to create a paginated Zod schema for an item type.\n */\nexport function createPaginatedSchema<ItemType extends z.ZodTypeAny>(itemSchema: ItemType) {\n\treturn z.object({\n\t\tmetadata: z\n\t\t\t.object({\n\t\t\t\tpage: z.number(),\n\t\t\t\tsize: z.number(),\n\t\t\t\ttotalElements: z.number(),\n\t\t\t\ttotalPages: z.number(),\n\t\t\t})\n\t\t\t.catchall(z.string().or(z.number()).or(z.boolean()).or(z.null()).or(z.undefined())),\n\t\titems: z.array(itemSchema),\n\t});\n}\n\nexport interface RawPaginatedResult<T extends AnyParamConstructor<any>> {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t\t// Use a more specific index signature\n\t\t[key: string]: string | number | boolean | null | undefined;\n\t};\n\tdocuments: DocumentType<T>[];\n}\n\n/**\n * The common pagination options.\n */\nexport interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {\n\tquery?: FilterQuery<DocumentType<TClass>>;\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tselect?: Record<string, 0 | 1>;\n\tpopulate?: PopulateOptions | (PopulateOptions | string)[];\n}\n\n/**\n * This internal function wraps the common query logic:\n * - filter, page, size, sort, populate\n * - fetch documents, count documents\n * - compute totalPages\n * Returns a standard object with `metadata` & `documents`.\n */\nasync function _basePaginate<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\toptions: PaginatorOptions<T>\n): Promise<RawPaginatedResult<T>> {\n\tconst { query = {}, page = 1, size = 10, sort = {}, select, populate } = options;\n\n\tconst skip = (page - 1) * size;\n\n\tlet result = model.find(query).sort(sort).skip(skip).limit(size);\n\n\tif (select) {\n\t\tresult = result.select(select) as any;\n\t}\n\tif (populate) {\n\t\tresult = result.populate(populate);\n\t}\n\n\tconst [documents, totalElements] = await Promise.all([result.exec(), model.countDocuments(query)]);\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: documents as unknown as DocumentType<T>[],\n\t};\n}\n\n/**\n * Creates a paginator returning raw documents.\n *\n * @param model The Typegoose model\n * @returns A function that, when passed `PaginatorOptions`, returns raw docs + metadata.\n */\nexport function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>\n) {\n\treturn async function paginate(options: PaginatorOptions<T>): Promise<RawPaginatedResult<T>> {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\treturn {\n\t\t\tmetadata,\n\t\t\tdocuments,\n\t\t};\n\t};\n}\n\n/**\n * Creates a paginator that returns Zod-validated items.\n *\n * @param model The Typegoose model\n * @param itemSchema A Zod schema describing the shape of each item\n * @param transformFn Optional transform function to convert raw doc -> item\n */\nexport function createPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\titemSchema: z.ZodTypeAny,\n\ttransformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>\n) {\n\tconst PaginatedSchema = createPaginatedSchema(itemSchema);\n\n\treturn async function paginate(options: PaginatorOptions<T>) {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\tconst items = transformFn ? documents.map(transformFn) : documents;\n\n\t\tconst paginatedResult = {\n\t\t\tmetadata,\n\t\t\titems,\n\t\t};\n\n\t\treturn PaginatedSchema.parse(paginatedResult);\n\t};\n}\nexport async function paginateAggregation(\n\tmodel: any,\n\tpipeline: any[],\n\tpage: number = 1,\n\tsize: number = 10,\n\tsort?: any,\n\tpopulateOptions?: any\n) {\n\t// Calculate skip and limit based on the page and size\n\tconst skip = (page - 1) * size;\n\tconst limit = size;\n\n\t// Copy the pipeline to avoid mutation\n\tconst pipelineWithCount = [...pipeline];\n\n\t// Step 1: Calculate total count\n\tpipelineWithCount.push({ $count: 'totalCount' });\n\n\t// Step 2: Execute to get total count\n\tconst totalCountResult = await model.aggregate(pipelineWithCount).exec();\n\tconst totalElements = totalCountResult?.[0]?.totalCount || 0;\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\t// Step 3: Apply pagination to the original pipeline\n\tconst paginatedPipeline = [...pipeline];\n\n\tif (sort && Object.keys(sort).length > 0) {\n\t\tpaginatedPipeline.push({ $sort: sort });\n\t}\n\n\tpaginatedPipeline.push({ $skip: skip });\n\tpaginatedPipeline.push({ $limit: limit });\n\n\t// Step 4: Execute the paginated pipeline\n\tconst data = await model.aggregate(paginatedPipeline).exec();\n\n\t// Step 5: Optional populate\n\tconst populatedData = populateOptions ? await model.populate(data, populateOptions) : data;\n\n\t// Return the paginated data with metadata\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: populatedData,\n\t};\n}\n\n/**\n * Generic pagination function for Mongoose models or arrays\n */\nexport async function customPaginate<T extends Document>(\n\toptions: CustomPaginatorOptions<T>,\n\tmodel?: Model<T>\n): Promise<CustomPaginatedResponse<any>> {\n\tconst page = options.page && options.page > 0 ? options.page : 1;\n\tconst size = options.size && options.size > 0 ? options.size : 10;\n\n\tlet documents: T[] = [];\n\tlet totalElements = 0;\n\n\tif (model) {\n\t\t// Mongoose query\n\t\tlet query: any = model.find(options.query || {});\n\n\t\tif (options.select) query = query.select(options.select);\n\t\tif (options.populate) query = query.populate(options.populate as any);\n\t\tif (options.sort) query = query.sort(options.sort);\n\n\t\ttotalElements = await model.countDocuments(options.query || {});\n\t\tdocuments = await query.skip((page - 1) * size).limit(size);\n\t} else if (Array.isArray(options.query)) {\n\t\t// In-memory array\n\t\ttotalElements = options.query.length;\n\t\tdocuments = options.query.slice((page - 1) * size, page * size);\n\t} else {\n\t\tthrow new Error('Either a Mongoose model or array must be provided');\n\t}\n\n\t// Apply optional transform\n\tif (options.transform) {\n\t\tdocuments = documents.map(options.transform);\n\t}\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tdocuments,\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"pagination.js","sourceRoot":"/","sources":["utilities/pagination.ts"],"names":[],"mappings":";;AASA,sDAYC;AAuED,4EAWC;AASD,sDAmBC;AACD,kDAkDC;AAKD,wCA4CC;AAvOD,6BAAwB;AASxB,SAAgB,qBAAqB,CAAgC,UAAoB;IACxF,OAAO,OAAC,CAAC,MAAM,CAAC;QACf,QAAQ,EAAE,OAAC;aACT,MAAM,CAAC;YACP,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,IAAI,EAAE,OAAC,CAAC,MAAM,EAAE;YAChB,aAAa,EAAE,OAAC,CAAC,MAAM,EAAE;YACzB,UAAU,EAAE,OAAC,CAAC,MAAM,EAAE;SACtB,CAAC;aACD,QAAQ,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,EAAE,CAAC,OAAC,CAAC,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,OAAC,CAAC,SAAS,EAAE,CAAC,CAAC;QACpF,KAAK,EAAE,OAAC,CAAC,KAAK,CAAC,UAAU,CAAC;KAC1B,CAAC,CAAC;AACJ,CAAC;AAiCD,KAAK,UAAU,aAAa,CAC3B,KAAyB,EACzB,OAA4B;IAE5B,MAAM,EAAE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AACH,CAAC","sourcesContent":["import { z } from 'zod';\nimport { ClientSession, FilterQuery, PopulateOptions, Model } from 'mongoose';\nimport { AnyParamConstructor } from '@typegoose/typegoose/lib/types';\nimport { DocumentType, ReturnModelType } from '@typegoose/typegoose';\nimport { CustomPaginatedResponse, CustomPaginatorOptions } from './validation';\n\n/**\n * A helper to create a paginated Zod schema for an item type.\n */\nexport function createPaginatedSchema<ItemType extends z.ZodTypeAny>(itemSchema: ItemType) {\n\treturn z.object({\n\t\tmetadata: z\n\t\t\t.object({\n\t\t\t\tpage: z.number(),\n\t\t\t\tsize: z.number(),\n\t\t\t\ttotalElements: z.number(),\n\t\t\t\ttotalPages: z.number(),\n\t\t\t})\n\t\t\t.catchall(z.string().or(z.number()).or(z.boolean()).or(z.null()).or(z.undefined())),\n\t\titems: z.array(itemSchema),\n\t});\n}\n\nexport interface RawPaginatedResult<T extends AnyParamConstructor<any>> {\n\tmetadata: {\n\t\tpage: number;\n\t\tsize: number;\n\t\ttotalElements: number;\n\t\ttotalPages: number;\n\t\t// Use a more specific index signature\n\t\t[key: string]: string | number | boolean | null | undefined;\n\t};\n\tdocuments: DocumentType<T>[];\n}\n\n/**\n * The common pagination options.\n */\nexport interface PaginatorOptions<TClass extends AnyParamConstructor<any>> {\n\tquery?: FilterQuery<DocumentType<TClass>>;\n\tpage?: number;\n\tsize?: number;\n\tsort?: Record<string, 1 | -1>;\n\tselect?: Record<string, 0 | 1>;\n\tpopulate?: PopulateOptions | (PopulateOptions | string)[];\n}\n\n/**\n * This internal function wraps the common query logic:\n * - filter, page, size, sort, populate\n * - fetch documents, count documents\n * - compute totalPages\n * Returns a standard object with `metadata` & `documents`.\n */\nasync function _basePaginate<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\toptions: PaginatorOptions<T>\n): Promise<RawPaginatedResult<T>> {\n\tconst { query = {}, page = 1, size = 10, sort = {}, select, populate } = options;\n\n\tconst skip = (page - 1) * size;\n\n\tlet result = model.find(query).sort(sort).skip(skip).limit(size);\n\n\tif (select) {\n\t\tresult = result.select(select) as any;\n\t}\n\tif (populate) {\n\t\tresult = result.populate(populate);\n\t}\n\n\tconst [documents, totalElements] = await Promise.all([result.exec(), model.countDocuments(query)]);\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: documents as unknown as DocumentType<T>[],\n\t};\n}\n\n/**\n * Creates a paginator returning raw documents.\n *\n * @param model The Typegoose model\n * @returns A function that, when passed `PaginatorOptions`, returns raw docs + metadata.\n */\nexport function createRawDocumentPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>\n) {\n\treturn async function paginate(options: PaginatorOptions<T>): Promise<RawPaginatedResult<T>> {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\treturn {\n\t\t\tmetadata,\n\t\t\tdocuments,\n\t\t};\n\t};\n}\n\n/**\n * Creates a paginator that returns Zod-validated items.\n *\n * @param model The Typegoose model\n * @param itemSchema A Zod schema describing the shape of each item\n * @param transformFn Optional transform function to convert raw doc -> item\n */\nexport function createPaginatorObject<T extends AnyParamConstructor<any>>(\n\tmodel: ReturnModelType<T>,\n\titemSchema: z.ZodTypeAny,\n\ttransformFn?: (doc: DocumentType<T>) => z.infer<typeof itemSchema>\n) {\n\tconst PaginatedSchema = createPaginatedSchema(itemSchema);\n\n\treturn async function paginate(options: PaginatorOptions<T>) {\n\t\tconst { metadata, documents } = await _basePaginate(model, options);\n\n\t\tconst items = transformFn ? documents.map(transformFn) : documents;\n\n\t\tconst paginatedResult = {\n\t\t\tmetadata,\n\t\t\titems,\n\t\t};\n\n\t\treturn PaginatedSchema.parse(paginatedResult);\n\t};\n}\nexport async function paginateAggregation(\n\tmodel: any,\n\tpipeline: any[],\n\tpage: number = 1,\n\tsize: number = 10,\n\tsort?: any,\n\tpopulateOptions?: any,\n\tsession?: ClientSession | null\n) {\n\t// Calculate skip and limit based on the page and size\n\tconst skip = (page - 1) * size;\n\tconst limit = size;\n\n\t// Copy the pipeline to avoid mutation\n\tconst pipelineWithCount = [...pipeline];\n\n\t// Step 1: Calculate total count\n\tpipelineWithCount.push({ $count: 'totalCount' });\n\n\t// Step 2: Execute to get total count\n\tconst totalCountResult = await model.aggregate(pipelineWithCount).session(session ?? null).exec();\n\tconst totalElements = totalCountResult?.[0]?.totalCount || 0;\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\t// Step 3: Apply pagination to the original pipeline\n\tconst paginatedPipeline = [...pipeline];\n\n\tif (sort && Object.keys(sort).length > 0) {\n\t\tpaginatedPipeline.push({ $sort: sort });\n\t}\n\n\tpaginatedPipeline.push({ $skip: skip });\n\tpaginatedPipeline.push({ $limit: limit });\n\n\t// Step 4: Execute the paginated pipeline\n\tconst data = await model.aggregate(paginatedPipeline).session(session ?? null).exec();\n\n\t// Step 5: Optional populate\n\tconst populatedData = populateOptions ? await model.populate(data, populateOptions) : data;\n\n\t// Return the paginated data with metadata\n\treturn {\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t\tdocuments: populatedData,\n\t};\n}\n\n/**\n * Generic pagination function for Mongoose models or arrays\n */\nexport async function customPaginate<T extends Document>(\n\toptions: CustomPaginatorOptions<T>,\n\tmodel?: Model<T>\n): Promise<CustomPaginatedResponse<any>> {\n\tconst page = options.page && options.page > 0 ? options.page : 1;\n\tconst size = options.size && options.size > 0 ? options.size : 10;\n\n\tlet documents: T[] = [];\n\tlet totalElements = 0;\n\n\tif (model) {\n\t\t// Mongoose query\n\t\tlet query: any = model.find(options.query || {});\n\n\t\tif (options.select) query = query.select(options.select);\n\t\tif (options.populate) query = query.populate(options.populate as any);\n\t\tif (options.sort) query = query.sort(options.sort);\n\n\t\ttotalElements = await model.countDocuments(options.query || {});\n\t\tdocuments = await query.skip((page - 1) * size).limit(size);\n\t} else if (Array.isArray(options.query)) {\n\t\t// In-memory array\n\t\ttotalElements = options.query.length;\n\t\tdocuments = options.query.slice((page - 1) * size, page * size);\n\t} else {\n\t\tthrow new Error('Either a Mongoose model or array must be provided');\n\t}\n\n\t// Apply optional transform\n\tif (options.transform) {\n\t\tdocuments = documents.map(options.transform);\n\t}\n\n\tconst totalPages = Math.ceil(totalElements / size);\n\n\treturn {\n\t\tdocuments,\n\t\tmetadata: {\n\t\t\tpage,\n\t\t\tsize,\n\t\t\ttotalElements,\n\t\t\ttotalPages,\n\t\t},\n\t};\n}\n"]}
|