@meghjs/core 0.5.4 → 0.5.5
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/README.md +32 -12
- package/dist/common/exceptions/http-exceptions.d.ts +1 -50
- package/dist/common/exceptions/http-exceptions.js +15 -80
- package/dist/common/exceptions/http-exceptions.js.map +1 -1
- package/dist/common/utils/compiled-validation.d.ts +43 -0
- package/dist/common/utils/compiled-validation.js +298 -0
- package/dist/common/utils/compiled-validation.js.map +1 -0
- package/dist/common/utils/object-utils.d.ts +4 -0
- package/dist/common/utils/object-utils.js +44 -7
- package/dist/common/utils/object-utils.js.map +1 -1
- package/dist/common/utils/path-utils.d.ts +7 -0
- package/dist/common/utils/path-utils.js +15 -0
- package/dist/common/utils/path-utils.js.map +1 -1
- package/dist/config/environment-variables.d.ts +2 -0
- package/dist/config/environment-variables.js +23 -12
- package/dist/config/environment-variables.js.map +1 -1
- package/dist/core/application.d.ts +89 -6
- package/dist/core/application.js +149 -72
- package/dist/core/application.js.map +1 -1
- package/dist/core/interfaces.d.ts +48 -1
- package/dist/core/router.d.ts +59 -5
- package/dist/core/router.js +233 -109
- package/dist/core/router.js.map +1 -1
- package/dist/core/testing.js +2 -12
- package/dist/core/testing.js.map +1 -1
- package/dist/core/types.d.ts +6 -0
- package/dist/errors/error-handler.d.ts +56 -0
- package/dist/errors/error-handler.js +206 -0
- package/dist/errors/error-handler.js.map +1 -0
- package/dist/errors/exception-filter.d.ts +96 -0
- package/dist/errors/exception-filter.js +68 -0
- package/dist/errors/exception-filter.js.map +1 -0
- package/dist/errors/http-exceptions.d.ts +413 -0
- package/dist/errors/http-exceptions.js +155 -0
- package/dist/errors/http-exceptions.js.map +1 -0
- package/dist/errors/index.d.ts +4 -0
- package/dist/errors/index.js +24 -0
- package/dist/errors/index.js.map +1 -0
- package/dist/events/event-subscriber.js +14 -3
- package/dist/events/event-subscriber.js.map +1 -1
- package/dist/events/socket-dispatcher.d.ts +1 -1
- package/dist/events/socket-dispatcher.js +1 -1
- package/dist/events/socket-dispatcher.js.map +1 -1
- package/dist/http/params.js +3 -1
- package/dist/http/params.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +4 -1
- package/dist/index.js.map +1 -1
- package/dist/observability/health.d.ts +45 -0
- package/dist/observability/health.js +74 -0
- package/dist/observability/health.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.js +5 -0
- package/dist/observability/index.js.map +1 -1
- package/dist/observability/logger.js +8 -1
- package/dist/observability/logger.js.map +1 -1
- package/dist/observability/request-context.d.ts +29 -0
- package/dist/observability/request-context.js +54 -0
- package/dist/observability/request-context.js.map +1 -0
- package/dist/openapi/swagger-schema.js +21 -2
- package/dist/openapi/swagger-schema.js.map +1 -1
- package/dist/orm/connect.d.ts +2 -0
- package/dist/orm/connect.js +6 -1
- package/dist/orm/connect.js.map +1 -1
- package/dist/orm/plugin.js +2 -0
- package/dist/orm/plugin.js.map +1 -1
- package/dist/plugins/plugin.d.ts +3 -0
- package/dist/plugins/plugin.js.map +1 -1
- package/dist/plugins/registry.js +1 -0
- package/dist/plugins/registry.js.map +1 -1
- package/dist/validator/compat.d.ts +5 -0
- package/dist/validator/compat.js +42 -0
- package/dist/validator/compat.js.map +1 -0
- package/dist/validator/compiler.d.ts +20 -0
- package/dist/validator/compiler.js +219 -0
- package/dist/validator/compiler.js.map +1 -0
- package/dist/validator/decorators.d.ts +81 -0
- package/dist/validator/decorators.js +377 -0
- package/dist/validator/decorators.js.map +1 -0
- package/dist/validator/index.d.ts +16 -0
- package/dist/validator/index.js +36 -0
- package/dist/validator/index.js.map +1 -0
- package/dist/validator/is-email.d.ts +25 -0
- package/dist/validator/is-email.js +204 -0
- package/dist/validator/is-email.js.map +1 -0
- package/dist/validator/messages.d.ts +20 -0
- package/dist/validator/messages.js +186 -0
- package/dist/validator/messages.js.map +1 -0
- package/dist/validator/metadata.d.ts +118 -0
- package/dist/validator/metadata.js +153 -0
- package/dist/validator/metadata.js.map +1 -0
- package/dist/validator/transform.d.ts +29 -0
- package/dist/validator/transform.js +210 -0
- package/dist/validator/transform.js.map +1 -0
- package/package.json +8 -3
|
@@ -0,0 +1,413 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @copyright 2024
|
|
3
|
+
* @author Tareq Hossain
|
|
4
|
+
* @email xtrinsic96@gmail.com
|
|
5
|
+
* @url https://github.com/xtareq
|
|
6
|
+
*/
|
|
7
|
+
/** Extra settings for an HTTP exception. */
|
|
8
|
+
export interface HttpExceptionOptions {
|
|
9
|
+
/** The underlying error, kept for logs (`error.cause`). Never sent to clients. */
|
|
10
|
+
cause?: unknown;
|
|
11
|
+
/** Response headers to set, such as `Retry-After` or `WWW-Authenticate`. */
|
|
12
|
+
headers?: Record<string, string | number | string[]>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Base class for errors that map to an HTTP response.
|
|
16
|
+
*
|
|
17
|
+
* `message` may be a string or an object. An object is sent as `data` and
|
|
18
|
+
* stringified into `error.message`.
|
|
19
|
+
*/
|
|
20
|
+
export declare abstract class BaseHttpException extends Error {
|
|
21
|
+
code: number;
|
|
22
|
+
name: string;
|
|
23
|
+
payload: any;
|
|
24
|
+
headers?: Record<string, string | number | string[]>;
|
|
25
|
+
constructor(message: any, options?: HttpExceptionOptions);
|
|
26
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
27
|
+
get statusCode(): number;
|
|
28
|
+
isCustomException(): boolean;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* An HTTP exception with any status code, for statuses without a dedicated
|
|
32
|
+
* class.
|
|
33
|
+
*
|
|
34
|
+
* throw new HttpException(402, "Payment required");
|
|
35
|
+
*/
|
|
36
|
+
export declare class HttpException extends BaseHttpException {
|
|
37
|
+
constructor(status: number, message?: any, options?: HttpExceptionOptions);
|
|
38
|
+
}
|
|
39
|
+
declare const BadRequestException_base: {
|
|
40
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
41
|
+
name: string;
|
|
42
|
+
code: number;
|
|
43
|
+
payload: any;
|
|
44
|
+
headers?: Record<string, string | number | string[]>;
|
|
45
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
46
|
+
get statusCode(): number;
|
|
47
|
+
isCustomException(): boolean;
|
|
48
|
+
message: string;
|
|
49
|
+
stack?: string;
|
|
50
|
+
cause?: unknown;
|
|
51
|
+
};
|
|
52
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
53
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
54
|
+
stackTraceLimit: number;
|
|
55
|
+
};
|
|
56
|
+
export declare class BadRequestException extends BadRequestException_base {
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A request that failed validation (400).
|
|
60
|
+
*
|
|
61
|
+
* Pass the individual issues as `errors` to have them sent in the response's
|
|
62
|
+
* `errors` field.
|
|
63
|
+
*/
|
|
64
|
+
export declare class ValidationErrorException extends BadRequestException {
|
|
65
|
+
name: string;
|
|
66
|
+
errors?: unknown[];
|
|
67
|
+
constructor(message?: any, errors?: unknown[], options?: HttpExceptionOptions);
|
|
68
|
+
}
|
|
69
|
+
declare const UnauthorizedException_base: {
|
|
70
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
71
|
+
name: string;
|
|
72
|
+
code: number;
|
|
73
|
+
payload: any;
|
|
74
|
+
headers?: Record<string, string | number | string[]>;
|
|
75
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
76
|
+
get statusCode(): number;
|
|
77
|
+
isCustomException(): boolean;
|
|
78
|
+
message: string;
|
|
79
|
+
stack?: string;
|
|
80
|
+
cause?: unknown;
|
|
81
|
+
};
|
|
82
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
83
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
84
|
+
stackTraceLimit: number;
|
|
85
|
+
};
|
|
86
|
+
export declare class UnauthorizedException extends UnauthorizedException_base {
|
|
87
|
+
}
|
|
88
|
+
declare const ForbiddenException_base: {
|
|
89
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
90
|
+
name: string;
|
|
91
|
+
code: number;
|
|
92
|
+
payload: any;
|
|
93
|
+
headers?: Record<string, string | number | string[]>;
|
|
94
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
95
|
+
get statusCode(): number;
|
|
96
|
+
isCustomException(): boolean;
|
|
97
|
+
message: string;
|
|
98
|
+
stack?: string;
|
|
99
|
+
cause?: unknown;
|
|
100
|
+
};
|
|
101
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
102
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
103
|
+
stackTraceLimit: number;
|
|
104
|
+
};
|
|
105
|
+
export declare class ForbiddenException extends ForbiddenException_base {
|
|
106
|
+
}
|
|
107
|
+
declare const NotFoundException_base: {
|
|
108
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
109
|
+
name: string;
|
|
110
|
+
code: number;
|
|
111
|
+
payload: any;
|
|
112
|
+
headers?: Record<string, string | number | string[]>;
|
|
113
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
114
|
+
get statusCode(): number;
|
|
115
|
+
isCustomException(): boolean;
|
|
116
|
+
message: string;
|
|
117
|
+
stack?: string;
|
|
118
|
+
cause?: unknown;
|
|
119
|
+
};
|
|
120
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
121
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
122
|
+
stackTraceLimit: number;
|
|
123
|
+
};
|
|
124
|
+
export declare class NotFoundException extends NotFoundException_base {
|
|
125
|
+
}
|
|
126
|
+
declare const MethodNotAllowedException_base: {
|
|
127
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
128
|
+
name: string;
|
|
129
|
+
code: number;
|
|
130
|
+
payload: any;
|
|
131
|
+
headers?: Record<string, string | number | string[]>;
|
|
132
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
133
|
+
get statusCode(): number;
|
|
134
|
+
isCustomException(): boolean;
|
|
135
|
+
message: string;
|
|
136
|
+
stack?: string;
|
|
137
|
+
cause?: unknown;
|
|
138
|
+
};
|
|
139
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
140
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
141
|
+
stackTraceLimit: number;
|
|
142
|
+
};
|
|
143
|
+
export declare class MethodNotAllowedException extends MethodNotAllowedException_base {
|
|
144
|
+
}
|
|
145
|
+
declare const NotAcceptableException_base: {
|
|
146
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
147
|
+
name: string;
|
|
148
|
+
code: number;
|
|
149
|
+
payload: any;
|
|
150
|
+
headers?: Record<string, string | number | string[]>;
|
|
151
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
152
|
+
get statusCode(): number;
|
|
153
|
+
isCustomException(): boolean;
|
|
154
|
+
message: string;
|
|
155
|
+
stack?: string;
|
|
156
|
+
cause?: unknown;
|
|
157
|
+
};
|
|
158
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
159
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
160
|
+
stackTraceLimit: number;
|
|
161
|
+
};
|
|
162
|
+
export declare class NotAcceptableException extends NotAcceptableException_base {
|
|
163
|
+
}
|
|
164
|
+
declare const RequestTimeoutException_base: {
|
|
165
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
166
|
+
name: string;
|
|
167
|
+
code: number;
|
|
168
|
+
payload: any;
|
|
169
|
+
headers?: Record<string, string | number | string[]>;
|
|
170
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
171
|
+
get statusCode(): number;
|
|
172
|
+
isCustomException(): boolean;
|
|
173
|
+
message: string;
|
|
174
|
+
stack?: string;
|
|
175
|
+
cause?: unknown;
|
|
176
|
+
};
|
|
177
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
178
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
179
|
+
stackTraceLimit: number;
|
|
180
|
+
};
|
|
181
|
+
export declare class RequestTimeoutException extends RequestTimeoutException_base {
|
|
182
|
+
}
|
|
183
|
+
declare const ConflictException_base: {
|
|
184
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
185
|
+
name: string;
|
|
186
|
+
code: number;
|
|
187
|
+
payload: any;
|
|
188
|
+
headers?: Record<string, string | number | string[]>;
|
|
189
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
190
|
+
get statusCode(): number;
|
|
191
|
+
isCustomException(): boolean;
|
|
192
|
+
message: string;
|
|
193
|
+
stack?: string;
|
|
194
|
+
cause?: unknown;
|
|
195
|
+
};
|
|
196
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
197
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
198
|
+
stackTraceLimit: number;
|
|
199
|
+
};
|
|
200
|
+
export declare class ConflictException extends ConflictException_base {
|
|
201
|
+
}
|
|
202
|
+
declare const GoneException_base: {
|
|
203
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
204
|
+
name: string;
|
|
205
|
+
code: number;
|
|
206
|
+
payload: any;
|
|
207
|
+
headers?: Record<string, string | number | string[]>;
|
|
208
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
209
|
+
get statusCode(): number;
|
|
210
|
+
isCustomException(): boolean;
|
|
211
|
+
message: string;
|
|
212
|
+
stack?: string;
|
|
213
|
+
cause?: unknown;
|
|
214
|
+
};
|
|
215
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
216
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
217
|
+
stackTraceLimit: number;
|
|
218
|
+
};
|
|
219
|
+
export declare class GoneException extends GoneException_base {
|
|
220
|
+
}
|
|
221
|
+
declare const PayloadTooLargeException_base: {
|
|
222
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
223
|
+
name: string;
|
|
224
|
+
code: number;
|
|
225
|
+
payload: any;
|
|
226
|
+
headers?: Record<string, string | number | string[]>;
|
|
227
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
228
|
+
get statusCode(): number;
|
|
229
|
+
isCustomException(): boolean;
|
|
230
|
+
message: string;
|
|
231
|
+
stack?: string;
|
|
232
|
+
cause?: unknown;
|
|
233
|
+
};
|
|
234
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
235
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
236
|
+
stackTraceLimit: number;
|
|
237
|
+
};
|
|
238
|
+
export declare class PayloadTooLargeException extends PayloadTooLargeException_base {
|
|
239
|
+
}
|
|
240
|
+
declare const UnsupportedMediaTypeException_base: {
|
|
241
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
242
|
+
name: string;
|
|
243
|
+
code: number;
|
|
244
|
+
payload: any;
|
|
245
|
+
headers?: Record<string, string | number | string[]>;
|
|
246
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
247
|
+
get statusCode(): number;
|
|
248
|
+
isCustomException(): boolean;
|
|
249
|
+
message: string;
|
|
250
|
+
stack?: string;
|
|
251
|
+
cause?: unknown;
|
|
252
|
+
};
|
|
253
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
254
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
255
|
+
stackTraceLimit: number;
|
|
256
|
+
};
|
|
257
|
+
export declare class UnsupportedMediaTypeException extends UnsupportedMediaTypeException_base {
|
|
258
|
+
}
|
|
259
|
+
declare const UnprocessableEntityException_base: {
|
|
260
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
261
|
+
name: string;
|
|
262
|
+
code: number;
|
|
263
|
+
payload: any;
|
|
264
|
+
headers?: Record<string, string | number | string[]>;
|
|
265
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
266
|
+
get statusCode(): number;
|
|
267
|
+
isCustomException(): boolean;
|
|
268
|
+
message: string;
|
|
269
|
+
stack?: string;
|
|
270
|
+
cause?: unknown;
|
|
271
|
+
};
|
|
272
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
273
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
274
|
+
stackTraceLimit: number;
|
|
275
|
+
};
|
|
276
|
+
export declare class UnprocessableEntityException extends UnprocessableEntityException_base {
|
|
277
|
+
}
|
|
278
|
+
declare const TooManyRequestsException_base: {
|
|
279
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
280
|
+
name: string;
|
|
281
|
+
code: number;
|
|
282
|
+
payload: any;
|
|
283
|
+
headers?: Record<string, string | number | string[]>;
|
|
284
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
285
|
+
get statusCode(): number;
|
|
286
|
+
isCustomException(): boolean;
|
|
287
|
+
message: string;
|
|
288
|
+
stack?: string;
|
|
289
|
+
cause?: unknown;
|
|
290
|
+
};
|
|
291
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
292
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
293
|
+
stackTraceLimit: number;
|
|
294
|
+
};
|
|
295
|
+
export declare class TooManyRequestsException extends TooManyRequestsException_base {
|
|
296
|
+
}
|
|
297
|
+
declare const InternalErrorException_base: {
|
|
298
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
299
|
+
name: string;
|
|
300
|
+
code: number;
|
|
301
|
+
payload: any;
|
|
302
|
+
headers?: Record<string, string | number | string[]>;
|
|
303
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
304
|
+
get statusCode(): number;
|
|
305
|
+
isCustomException(): boolean;
|
|
306
|
+
message: string;
|
|
307
|
+
stack?: string;
|
|
308
|
+
cause?: unknown;
|
|
309
|
+
};
|
|
310
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
311
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
312
|
+
stackTraceLimit: number;
|
|
313
|
+
};
|
|
314
|
+
export declare class InternalErrorException extends InternalErrorException_base {
|
|
315
|
+
}
|
|
316
|
+
declare const NotImplementedException_base: {
|
|
317
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
318
|
+
name: string;
|
|
319
|
+
code: number;
|
|
320
|
+
payload: any;
|
|
321
|
+
headers?: Record<string, string | number | string[]>;
|
|
322
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
323
|
+
get statusCode(): number;
|
|
324
|
+
isCustomException(): boolean;
|
|
325
|
+
message: string;
|
|
326
|
+
stack?: string;
|
|
327
|
+
cause?: unknown;
|
|
328
|
+
};
|
|
329
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
330
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
331
|
+
stackTraceLimit: number;
|
|
332
|
+
};
|
|
333
|
+
export declare class NotImplementedException extends NotImplementedException_base {
|
|
334
|
+
}
|
|
335
|
+
declare const BadGatewayException_base: {
|
|
336
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
337
|
+
name: string;
|
|
338
|
+
code: number;
|
|
339
|
+
payload: any;
|
|
340
|
+
headers?: Record<string, string | number | string[]>;
|
|
341
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
342
|
+
get statusCode(): number;
|
|
343
|
+
isCustomException(): boolean;
|
|
344
|
+
message: string;
|
|
345
|
+
stack?: string;
|
|
346
|
+
cause?: unknown;
|
|
347
|
+
};
|
|
348
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
349
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
350
|
+
stackTraceLimit: number;
|
|
351
|
+
};
|
|
352
|
+
export declare class BadGatewayException extends BadGatewayException_base {
|
|
353
|
+
}
|
|
354
|
+
declare const ServiceUnavailableException_base: {
|
|
355
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
356
|
+
name: string;
|
|
357
|
+
code: number;
|
|
358
|
+
payload: any;
|
|
359
|
+
headers?: Record<string, string | number | string[]>;
|
|
360
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
361
|
+
get statusCode(): number;
|
|
362
|
+
isCustomException(): boolean;
|
|
363
|
+
message: string;
|
|
364
|
+
stack?: string;
|
|
365
|
+
cause?: unknown;
|
|
366
|
+
};
|
|
367
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
368
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
369
|
+
stackTraceLimit: number;
|
|
370
|
+
};
|
|
371
|
+
export declare class ServiceUnavailableException extends ServiceUnavailableException_base {
|
|
372
|
+
}
|
|
373
|
+
declare const GatewayTimeoutException_base: {
|
|
374
|
+
new (message?: any, options?: HttpExceptionOptions): {
|
|
375
|
+
name: string;
|
|
376
|
+
code: number;
|
|
377
|
+
payload: any;
|
|
378
|
+
headers?: Record<string, string | number | string[]>;
|
|
379
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
380
|
+
get statusCode(): number;
|
|
381
|
+
isCustomException(): boolean;
|
|
382
|
+
message: string;
|
|
383
|
+
stack?: string;
|
|
384
|
+
cause?: unknown;
|
|
385
|
+
};
|
|
386
|
+
captureStackTrace(targetObject: object, constructorOpt?: Function): void;
|
|
387
|
+
prepareStackTrace(err: Error, stackTraces: NodeJS.CallSite[]): any;
|
|
388
|
+
stackTraceLimit: number;
|
|
389
|
+
};
|
|
390
|
+
export declare class GatewayTimeoutException extends GatewayTimeoutException_base {
|
|
391
|
+
}
|
|
392
|
+
export type HttpExceptionTypes = NotFoundException | BadRequestException | UnauthorizedException | InternalErrorException | ForbiddenException;
|
|
393
|
+
/** Factory shortcuts: `throw HttpExceptions.notFound("User not found")`. */
|
|
394
|
+
export declare const HttpExceptions: {
|
|
395
|
+
badRequest: (message?: any, options?: HttpExceptionOptions) => BadRequestException;
|
|
396
|
+
validationError: (message?: any, errors?: unknown[]) => ValidationErrorException;
|
|
397
|
+
unauthorized: (message?: any, options?: HttpExceptionOptions) => UnauthorizedException;
|
|
398
|
+
forbidden: (message?: any, options?: HttpExceptionOptions) => ForbiddenException;
|
|
399
|
+
notFound: (message?: any, options?: HttpExceptionOptions) => NotFoundException;
|
|
400
|
+
methodNotAllowed: (message?: any, options?: HttpExceptionOptions) => MethodNotAllowedException;
|
|
401
|
+
conflict: (message?: any, options?: HttpExceptionOptions) => ConflictException;
|
|
402
|
+
gone: (message?: any, options?: HttpExceptionOptions) => GoneException;
|
|
403
|
+
payloadTooLarge: (message?: any, options?: HttpExceptionOptions) => PayloadTooLargeException;
|
|
404
|
+
unsupportedMediaType: (message?: any, options?: HttpExceptionOptions) => UnsupportedMediaTypeException;
|
|
405
|
+
unprocessableEntity: (message?: any, options?: HttpExceptionOptions) => UnprocessableEntityException;
|
|
406
|
+
tooManyRequests: (message?: any, options?: HttpExceptionOptions) => TooManyRequestsException;
|
|
407
|
+
internalError: (message?: any, options?: HttpExceptionOptions) => InternalErrorException;
|
|
408
|
+
notImplemented: (message?: any, options?: HttpExceptionOptions) => NotImplementedException;
|
|
409
|
+
serviceUnavailable: (message?: any, options?: HttpExceptionOptions) => ServiceUnavailableException;
|
|
410
|
+
/** Any status: `HttpExceptions.status(402, "Payment required")`. */
|
|
411
|
+
status: (status: number, message?: any, options?: HttpExceptionOptions) => HttpException;
|
|
412
|
+
};
|
|
413
|
+
export {};
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* @copyright 2024
|
|
4
|
+
* @author Tareq Hossain
|
|
5
|
+
* @email xtrinsic96@gmail.com
|
|
6
|
+
* @url https://github.com/xtareq
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.HttpExceptions = exports.GatewayTimeoutException = exports.ServiceUnavailableException = exports.BadGatewayException = exports.NotImplementedException = exports.InternalErrorException = exports.TooManyRequestsException = exports.UnprocessableEntityException = exports.UnsupportedMediaTypeException = exports.PayloadTooLargeException = exports.GoneException = exports.ConflictException = exports.RequestTimeoutException = exports.NotAcceptableException = exports.MethodNotAllowedException = exports.NotFoundException = exports.ForbiddenException = exports.UnauthorizedException = exports.ValidationErrorException = exports.BadRequestException = exports.HttpException = exports.BaseHttpException = void 0;
|
|
10
|
+
/**
|
|
11
|
+
* Base class for errors that map to an HTTP response.
|
|
12
|
+
*
|
|
13
|
+
* `message` may be a string or an object. An object is sent as `data` and
|
|
14
|
+
* stringified into `error.message`.
|
|
15
|
+
*/
|
|
16
|
+
class BaseHttpException extends Error {
|
|
17
|
+
code = 500;
|
|
18
|
+
name = "HttpException";
|
|
19
|
+
payload;
|
|
20
|
+
headers;
|
|
21
|
+
constructor(message, options) {
|
|
22
|
+
const stringMessage = typeof message === "string" ? message : JSON.stringify(message);
|
|
23
|
+
super(stringMessage, options?.cause !== undefined ? { cause: options.cause } : undefined);
|
|
24
|
+
this.payload = typeof message === "string" ? { message } : message;
|
|
25
|
+
if (options?.headers)
|
|
26
|
+
this.headers = options.headers;
|
|
27
|
+
}
|
|
28
|
+
/** The HTTP status. Same as `code`; this name is what Fastify and most libraries read. */
|
|
29
|
+
get statusCode() {
|
|
30
|
+
return this.code;
|
|
31
|
+
}
|
|
32
|
+
isCustomException() {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.BaseHttpException = BaseHttpException;
|
|
37
|
+
/**
|
|
38
|
+
* An HTTP exception with any status code, for statuses without a dedicated
|
|
39
|
+
* class.
|
|
40
|
+
*
|
|
41
|
+
* throw new HttpException(402, "Payment required");
|
|
42
|
+
*/
|
|
43
|
+
class HttpException extends BaseHttpException {
|
|
44
|
+
constructor(status, message = "", options) {
|
|
45
|
+
super(message, options);
|
|
46
|
+
this.code = status;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
exports.HttpException = HttpException;
|
|
50
|
+
/**
|
|
51
|
+
* Declares a subclass with a fixed status and name. The class fields of each
|
|
52
|
+
* subclass run after `BaseHttpException`'s, so the status set here wins.
|
|
53
|
+
*/
|
|
54
|
+
function defineStatus(name, code, defaultMessage = "") {
|
|
55
|
+
return class extends BaseHttpException {
|
|
56
|
+
name = name;
|
|
57
|
+
code = code;
|
|
58
|
+
constructor(message = defaultMessage, options) {
|
|
59
|
+
super(message, options);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
// ─── 4xx ─────────────────────────────────────────────────────────────────────
|
|
64
|
+
class BadRequestException extends defineStatus("BadRequest", 400) {
|
|
65
|
+
}
|
|
66
|
+
exports.BadRequestException = BadRequestException;
|
|
67
|
+
/**
|
|
68
|
+
* A request that failed validation (400).
|
|
69
|
+
*
|
|
70
|
+
* Pass the individual issues as `errors` to have them sent in the response's
|
|
71
|
+
* `errors` field.
|
|
72
|
+
*/
|
|
73
|
+
class ValidationErrorException extends BadRequestException {
|
|
74
|
+
name = "ValidationError";
|
|
75
|
+
errors;
|
|
76
|
+
constructor(message = "Validation failed", errors, options) {
|
|
77
|
+
super(message, options);
|
|
78
|
+
if (errors)
|
|
79
|
+
this.errors = errors;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
exports.ValidationErrorException = ValidationErrorException;
|
|
83
|
+
class UnauthorizedException extends defineStatus("Unauthorized", 401) {
|
|
84
|
+
}
|
|
85
|
+
exports.UnauthorizedException = UnauthorizedException;
|
|
86
|
+
class ForbiddenException extends defineStatus("Forbidden", 403) {
|
|
87
|
+
}
|
|
88
|
+
exports.ForbiddenException = ForbiddenException;
|
|
89
|
+
class NotFoundException extends defineStatus("NotFound", 404) {
|
|
90
|
+
}
|
|
91
|
+
exports.NotFoundException = NotFoundException;
|
|
92
|
+
class MethodNotAllowedException extends defineStatus("MethodNotAllowed", 405) {
|
|
93
|
+
}
|
|
94
|
+
exports.MethodNotAllowedException = MethodNotAllowedException;
|
|
95
|
+
class NotAcceptableException extends defineStatus("NotAcceptable", 406) {
|
|
96
|
+
}
|
|
97
|
+
exports.NotAcceptableException = NotAcceptableException;
|
|
98
|
+
class RequestTimeoutException extends defineStatus("RequestTimeout", 408) {
|
|
99
|
+
}
|
|
100
|
+
exports.RequestTimeoutException = RequestTimeoutException;
|
|
101
|
+
class ConflictException extends defineStatus("Conflict", 409) {
|
|
102
|
+
}
|
|
103
|
+
exports.ConflictException = ConflictException;
|
|
104
|
+
class GoneException extends defineStatus("Gone", 410) {
|
|
105
|
+
}
|
|
106
|
+
exports.GoneException = GoneException;
|
|
107
|
+
class PayloadTooLargeException extends defineStatus("PayloadTooLarge", 413) {
|
|
108
|
+
}
|
|
109
|
+
exports.PayloadTooLargeException = PayloadTooLargeException;
|
|
110
|
+
class UnsupportedMediaTypeException extends defineStatus("UnsupportedMediaType", 415) {
|
|
111
|
+
}
|
|
112
|
+
exports.UnsupportedMediaTypeException = UnsupportedMediaTypeException;
|
|
113
|
+
class UnprocessableEntityException extends defineStatus("UnprocessableEntity", 422) {
|
|
114
|
+
}
|
|
115
|
+
exports.UnprocessableEntityException = UnprocessableEntityException;
|
|
116
|
+
class TooManyRequestsException extends defineStatus("TooManyRequests", 429) {
|
|
117
|
+
}
|
|
118
|
+
exports.TooManyRequestsException = TooManyRequestsException;
|
|
119
|
+
// ─── 5xx ─────────────────────────────────────────────────────────────────────
|
|
120
|
+
class InternalErrorException extends defineStatus("InternalError", 500, "Something going wrong") {
|
|
121
|
+
}
|
|
122
|
+
exports.InternalErrorException = InternalErrorException;
|
|
123
|
+
class NotImplementedException extends defineStatus("NotImplemented", 501) {
|
|
124
|
+
}
|
|
125
|
+
exports.NotImplementedException = NotImplementedException;
|
|
126
|
+
class BadGatewayException extends defineStatus("BadGateway", 502) {
|
|
127
|
+
}
|
|
128
|
+
exports.BadGatewayException = BadGatewayException;
|
|
129
|
+
class ServiceUnavailableException extends defineStatus("ServiceUnavailable", 503) {
|
|
130
|
+
}
|
|
131
|
+
exports.ServiceUnavailableException = ServiceUnavailableException;
|
|
132
|
+
class GatewayTimeoutException extends defineStatus("GatewayTimeout", 504) {
|
|
133
|
+
}
|
|
134
|
+
exports.GatewayTimeoutException = GatewayTimeoutException;
|
|
135
|
+
/** Factory shortcuts: `throw HttpExceptions.notFound("User not found")`. */
|
|
136
|
+
exports.HttpExceptions = {
|
|
137
|
+
badRequest: (message = "", options) => new BadRequestException(message, options),
|
|
138
|
+
validationError: (message = "", errors) => new ValidationErrorException(message, errors),
|
|
139
|
+
unauthorized: (message = "", options) => new UnauthorizedException(message, options),
|
|
140
|
+
forbidden: (message = "", options) => new ForbiddenException(message, options),
|
|
141
|
+
notFound: (message = "", options) => new NotFoundException(message, options),
|
|
142
|
+
methodNotAllowed: (message = "", options) => new MethodNotAllowedException(message, options),
|
|
143
|
+
conflict: (message = "", options) => new ConflictException(message, options),
|
|
144
|
+
gone: (message = "", options) => new GoneException(message, options),
|
|
145
|
+
payloadTooLarge: (message = "", options) => new PayloadTooLargeException(message, options),
|
|
146
|
+
unsupportedMediaType: (message = "", options) => new UnsupportedMediaTypeException(message, options),
|
|
147
|
+
unprocessableEntity: (message = "", options) => new UnprocessableEntityException(message, options),
|
|
148
|
+
tooManyRequests: (message = "", options) => new TooManyRequestsException(message, options),
|
|
149
|
+
internalError: (message = "", options) => new InternalErrorException(message, options),
|
|
150
|
+
notImplemented: (message = "", options) => new NotImplementedException(message, options),
|
|
151
|
+
serviceUnavailable: (message = "", options) => new ServiceUnavailableException(message, options),
|
|
152
|
+
/** Any status: `HttpExceptions.status(402, "Payment required")`. */
|
|
153
|
+
status: (status, message = "", options) => new HttpException(status, message, options),
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=http-exceptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-exceptions.js","sourceRoot":"","sources":["../../src/errors/http-exceptions.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAUH;;;;;GAKG;AACH,MAAsB,iBAAkB,SAAQ,KAAK;IACnD,IAAI,GAAW,GAAG,CAAC;IACnB,IAAI,GAAW,eAAe,CAAC;IAC/B,OAAO,CAAM;IACb,OAAO,CAA8C;IAErD,YAAY,OAAY,EAAE,OAA8B;QACtD,MAAM,aAAa,GACjB,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;QAClE,KAAK,CACH,aAAa,EACb,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CACpE,CAAC;QACF,IAAI,CAAC,OAAO,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC;QACnE,IAAI,OAAO,EAAE,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACvD,CAAC;IAED,0FAA0F;IAC1F,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,iBAAiB;QACf,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAzBD,8CAyBC;AAED;;;;;GAKG;AACH,MAAa,aAAc,SAAQ,iBAAiB;IAClD,YACE,MAAc,EACd,UAAe,EAAE,EACjB,OAA8B;QAE9B,KAAK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aAAa,EAAE,CAAC,UAAe,EAAE,EAAE,OAA8B,EAAE,EAAE,CACnE,IAAI,sBAAsB,CAAC,OAAO,EAAE,OAAO,CAAC;IAC9C,cAAc,EAAE,CAAC,UAAe,EAAE,EAAE,OAA8B,EAAE,EAAE,CACpE,IAAI,uBAAuB,CAAC,OAAO,EAAE,OAAO,CAAC;IAC/C,kBAAkB,EAAE,CAAC,UAAe,EAAE,EAAE,OAA8B,EAAE,EAAE,CACxE,IAAI,2BAA2B,CAAC,OAAO,EAAE,OAAO,CAAC;IACnD,oEAAoE;IACpE,MAAM,EAAE,CAAC,MAAc,EAAE,UAAe,EAAE,EAAE,OAA8B,EAAE,EAAE,CAC5E,IAAI,aAAa,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC;CAC9C,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.defaultErrorLogger = exports.defaultErrorResponse = exports.MeghErrorHandler = void 0;
|
|
18
|
+
__exportStar(require("./http-exceptions"), exports);
|
|
19
|
+
__exportStar(require("./exception-filter"), exports);
|
|
20
|
+
var error_handler_1 = require("./error-handler");
|
|
21
|
+
Object.defineProperty(exports, "MeghErrorHandler", { enumerable: true, get: function () { return error_handler_1.MeghErrorHandler; } });
|
|
22
|
+
Object.defineProperty(exports, "defaultErrorResponse", { enumerable: true, get: function () { return error_handler_1.defaultErrorResponse; } });
|
|
23
|
+
Object.defineProperty(exports, "defaultErrorLogger", { enumerable: true, get: function () { return error_handler_1.defaultErrorLogger; } });
|
|
24
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/errors/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,oDAAkC;AAClC,qDAAmC;AACnC,iDAIyB;AAHvB,iHAAA,gBAAgB,OAAA;AAChB,qHAAA,oBAAoB,OAAA;AACpB,mHAAA,kBAAkB,OAAA"}
|
|
@@ -19,6 +19,7 @@ exports.Subscribe = Subscribe;
|
|
|
19
19
|
const di_1 = require("../di");
|
|
20
20
|
const socket_dispatcher_1 = require("./socket-dispatcher");
|
|
21
21
|
require("reflect-metadata");
|
|
22
|
+
const internal_logger_1 = require("../observability/internal-logger");
|
|
22
23
|
const PRIVATE_META_KEY = "megh:private";
|
|
23
24
|
function PrivateChannel(channelResolver) {
|
|
24
25
|
return function (target, propertyKey) {
|
|
@@ -64,16 +65,26 @@ let EventSubscriberRegistry = class EventSubscriberRegistry {
|
|
|
64
65
|
const channel = isPrivateListener && channelResolver
|
|
65
66
|
? channelResolver(socket)
|
|
66
67
|
: event;
|
|
67
|
-
|
|
68
|
+
(0, internal_logger_1.internalLogger)("events").debug({
|
|
69
|
+
channel,
|
|
70
|
+
listener: `${instance.constructor?.name}.${methodName}`,
|
|
71
|
+
}, "Socket listener registered");
|
|
68
72
|
socket.on(channel, (payload) => {
|
|
69
|
-
|
|
73
|
+
// A failing listener must not become an unhandled rejection,
|
|
74
|
+
// which would take the whole process down.
|
|
75
|
+
Promise.resolve(this.socketContext.run(socket, async () => {
|
|
70
76
|
if (isPrivateListener) {
|
|
71
77
|
const user = socket.data.user;
|
|
72
78
|
if (!user)
|
|
73
79
|
return; // unauthorized
|
|
74
|
-
// optionally add more validation here
|
|
75
80
|
}
|
|
76
81
|
await instance[methodName](payload, socket.data);
|
|
82
|
+
})).catch((err) => {
|
|
83
|
+
(0, internal_logger_1.internalLogger)("events").error({
|
|
84
|
+
err,
|
|
85
|
+
channel,
|
|
86
|
+
listener: `${instance.constructor?.name}.${methodName}`,
|
|
87
|
+
}, "Socket listener failed");
|
|
77
88
|
});
|
|
78
89
|
});
|
|
79
90
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-subscriber.js","sourceRoot":"","sources":["../../src/events/event-subscriber.ts"],"names":[],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"event-subscriber.js","sourceRoot":"","sources":["../../src/events/event-subscriber.ts"],"names":[],"mappings":";;;;;;;;;;;;AASA,wCASC;AAED,8BAEC;AAED,8DAKC;AAID,4DAEC;AAED,oDAEC;AAED,8BAKC;AA9CD,8BAA8C;AAE9C,2DAA2D;AAE3D,4BAA0B;AAC1B,sEAAkE;AAElE,MAAM,gBAAgB,GAAG,cAAc,CAAC;AAExC,SAAgB,cAAc,CAAC,eAAyC;IACtE,OAAO,UAAU,MAAW,EAAE,WAAmB;QAC/C,OAAO,CAAC,cAAc,CAAC,gBAAgB,EAAE,IAAI,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;QACpE,OAAO,CAAC,cAAc,CACpB,mBAAmB,WAAW,EAAE,EAChC,eAAe,EACf,MAAM,CACP,CAAC;IACJ,CAAC,CAAC;AACJ,CAAC;AAED,SAAgB,SAAS,CAAC,MAAW,EAAE,WAAmB;IACxD,OAAO,OAAO,CAAC,WAAW,CAAC,gBAAgB,EAAE,MAAM,EAAE,WAAW,CAAC,IAAI,KAAK,CAAC;AAC7E,CAAC;AAED,SAAgB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