@catbee/utils 2.0.0-next.0 → 2.0.0-next.1

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 (97) hide show
  1. package/README.md +52 -16
  2. package/array/index.cjs +180 -71
  3. package/array/index.d.ts +293 -1
  4. package/array/index.mjs +171 -72
  5. package/async/index.cjs +92 -36
  6. package/async/index.d.ts +275 -1
  7. package/async/index.mjs +92 -36
  8. package/cache/index.cjs +1 -1
  9. package/cache/index.d.ts +155 -1
  10. package/cache/index.mjs +2 -2
  11. package/config/index.cjs +78 -64
  12. package/config/index.d.ts +64 -2
  13. package/config/index.mjs +76 -64
  14. package/context-store/index.d.ts +192 -1
  15. package/crypto/index.d.ts +163 -1
  16. package/date/index.cjs +46 -1
  17. package/date/index.d.ts +190 -1
  18. package/date/index.mjs +45 -2
  19. package/decorators/index.cjs +1156 -18
  20. package/decorators/index.d.ts +684 -1
  21. package/decorators/index.mjs +1156 -18
  22. package/dir/index.cjs +4 -3
  23. package/dir/index.d.ts +195 -1
  24. package/dir/index.mjs +4 -3
  25. package/env/index.cjs +10 -26
  26. package/env/index.d.ts +379 -1
  27. package/env/index.mjs +10 -26
  28. package/exception/index.d.ts +232 -1
  29. package/fs/index.cjs +70 -36
  30. package/fs/index.d.ts +205 -1
  31. package/fs/index.mjs +64 -34
  32. package/http-status-codes/index.d.ts +267 -1
  33. package/id/index.d.ts +37 -1
  34. package/index.cjs +3 -3
  35. package/index.d.ts +1 -1
  36. package/index.mjs +1 -1
  37. package/logger/index.cjs +11 -11
  38. package/logger/index.d.ts +189 -1
  39. package/logger/index.mjs +12 -12
  40. package/middleware/index.d.ts +103 -1
  41. package/obj/index.cjs +150 -162
  42. package/obj/index.d.ts +136 -1
  43. package/obj/index.mjs +150 -162
  44. package/package.json +11 -11
  45. package/performance/index.cjs +2 -2
  46. package/performance/index.d.ts +138 -1
  47. package/performance/index.mjs +2 -2
  48. package/request/index.cjs +1 -1
  49. package/request/index.d.ts +241 -2
  50. package/request/index.mjs +1 -1
  51. package/response/index.d.ts +318 -2
  52. package/server/index.cjs +27 -23
  53. package/server/index.d.ts +785 -4
  54. package/server/index.mjs +28 -23
  55. package/stream/index.d.ts +90 -1
  56. package/string/index.d.ts +102 -1
  57. package/type/index.cjs +1 -1
  58. package/type/index.d.ts +107 -1
  59. package/type/index.mjs +1 -1
  60. package/types/index.d.ts +774 -4
  61. package/url/index.cjs +2 -4
  62. package/url/index.d.ts +142 -1
  63. package/url/index.mjs +2 -4
  64. package/{validate → validation}/index.cjs +89 -42
  65. package/{validate/validate.utils.d.ts → validation/index.d.ts} +32 -23
  66. package/{validate → validation}/index.mjs +85 -42
  67. package/array/array.utils.d.ts +0 -191
  68. package/async/async.utils.d.ts +0 -296
  69. package/cache/cache.utils.d.ts +0 -176
  70. package/config/config.d.ts +0 -57
  71. package/context-store/context-store.utils.d.ts +0 -212
  72. package/crypto/crypto.utils.d.ts +0 -183
  73. package/date/date.utils.d.ts +0 -190
  74. package/decorators/decorators.utils.d.ts +0 -705
  75. package/dir/dir.utils.d.ts +0 -216
  76. package/env/env.utils.d.ts +0 -400
  77. package/exception/exception.utils.d.ts +0 -253
  78. package/fs/fs.utils.d.ts +0 -196
  79. package/http-status-codes/http-status-codes.d.ts +0 -289
  80. package/id/id.utils.d.ts +0 -59
  81. package/logger/logger.utils.d.ts +0 -210
  82. package/middleware/middleware.utils.d.ts +0 -123
  83. package/obj/obj.utils.d.ts +0 -156
  84. package/performance/performance.utils.d.ts +0 -159
  85. package/request/request.utils.d.ts +0 -109
  86. package/response/response.utils.d.ts +0 -186
  87. package/server/server.builder.d.ts +0 -531
  88. package/server/server.d.ts +0 -303
  89. package/stream/stream.utils.d.ts +0 -111
  90. package/string/string.utils.d.ts +0 -124
  91. package/type/type.utils.d.ts +0 -129
  92. package/types/api-response.d.ts +0 -175
  93. package/types/common.d.ts +0 -148
  94. package/types/config.d.ts +0 -88
  95. package/types/server.d.ts +0 -291
  96. package/url/url.utils.d.ts +0 -164
  97. package/validate/index.d.ts +0 -25
@@ -22,5 +22,244 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export * from './request.utils';
26
- export * from '../types/api-response';
25
+ import { Request } from 'express';
26
+ import { WithPagination as WithPagination$1 } from '@catbee/utils/response';
27
+
28
+ /**
29
+ * Options for parsing and validating request parameters.
30
+ */
31
+ interface ValidationOptions {
32
+ /** Whether to throw an error on validation failure */
33
+ throwOnError?: boolean;
34
+ /** Custom error message for validation failures */
35
+ errorMessage?: string;
36
+ /** Default value to use if parameter is missing */
37
+ defaultValue?: any;
38
+ /** Whether the parameter is required */
39
+ required?: boolean;
40
+ }
41
+ /**
42
+ * Result of a parameter validation operation.
43
+ */
44
+ interface ValidationResult<T> {
45
+ /** Whether validation was successful */
46
+ isValid: boolean;
47
+ /** The validated and potentially transformed value */
48
+ value: T | null;
49
+ /** Error message if validation failed */
50
+ error?: string;
51
+ }
52
+ /**
53
+ * Extracts pagination, sorting, and optional search params from a request.
54
+ *
55
+ * @param req - Express request
56
+ * @returns Object containing validated pagination, sorting, and additional query params
57
+ */
58
+ declare const getPaginationParams: <T = {}>(req: Request) => WithPagination$1<T>;
59
+ /**
60
+ * Safely parses a string parameter to a number.
61
+ *
62
+ * @param value - String value to parse
63
+ * @param options - Validation options
64
+ * @returns Validation result containing the parsed number or error
65
+ */
66
+ declare function parseNumberParam(value: string | undefined, options?: ValidationOptions): ValidationResult<number>;
67
+ /**
68
+ * Safely parses a string parameter to a boolean.
69
+ *
70
+ * @param value - String value to parse
71
+ * @param options - Validation options
72
+ * @returns Validation result containing the parsed boolean or error
73
+ */
74
+ declare function parseBooleanParam(value: string | undefined, options?: ValidationOptions): ValidationResult<boolean>;
75
+ /**
76
+ * Extracts pagination parameters from request query parameters.
77
+ *
78
+ * @param query - Query parameters object
79
+ * @param defaultPage - Default page number if not specified (defaults to 1)
80
+ * @param defaultLimit - Default per page size if not specified (defaults to 20)
81
+ * @param maxLimitSize - Maximum allowed per page size (defaults to 100)
82
+ * @returns Object containing validated page and limit
83
+ */
84
+ declare function extractPaginationParams(query: Record<string, string | string[]>, defaultPage?: number, defaultLimit?: number, maxLimitSize?: number): {
85
+ page: number;
86
+ limit: number;
87
+ };
88
+ /**
89
+ * Extracts sorting parameters from request query parameters.
90
+ *
91
+ * @param query - Query parameters object
92
+ * @param allowedFields - Array of field names that are allowed to be sorted
93
+ * @param defaultSort - Default sort configuration if not specified
94
+ * @returns Object containing sort field and direction
95
+ */
96
+ declare function extractSortParams(query: Record<string, string | string[]>, allowedFields: string[], defaultSort?: {
97
+ sortBy: string;
98
+ sortOrder: 'asc' | 'desc';
99
+ }): {
100
+ sortBy: string;
101
+ sortOrder: 'asc' | 'desc';
102
+ };
103
+ /**
104
+ * Extracts filter parameters from query parameters based on allowed filter fields.
105
+ *
106
+ * @param query - Query parameters object
107
+ * @param allowedFilters - Array of field names that are allowed to be used as filters
108
+ * @returns Object containing the filters as key-value pairs
109
+ */
110
+ declare function extractFilterParams(query: Record<string, string | string[]>, allowedFilters: string[]): Record<string, string | string[]>;
111
+
112
+ /**
113
+ * Generic API response format.
114
+ * Used to wrap any successful or failed response from the server.
115
+ */
116
+ interface ApiResponse<T = any> {
117
+ /** Payload returned from the API. Can be any shape depending on the endpoint. */
118
+ data: T | null;
119
+ /** Indicates whether an error occurred (true = error, false = success). */
120
+ error: boolean;
121
+ /** Success message describing the result of the operation. */
122
+ message: string;
123
+ /** Unique request ID for traceability in logs (e.g., from a middleware). */
124
+ requestId: string;
125
+ /** ISO timestamp when the response was generated. */
126
+ timestamp: string;
127
+ }
128
+ /**
129
+ * Generic pagination structure used for paged lists (e.g., /users?page=1).
130
+ */
131
+ interface Pagination<T = any> {
132
+ /** List of records for the current page. */
133
+ content: T[];
134
+ /** Metadata about the pagination state. */
135
+ pagination: {
136
+ /** Total number of records across all pages. */
137
+ totalRecords: number;
138
+ /** Total number of pages available. */
139
+ totalPages: number;
140
+ /** Current page number (1-based index). */
141
+ page: number;
142
+ /** Number of records per page. */
143
+ limit: number;
144
+ /** Field by which the data is sorted. */
145
+ sortBy: string;
146
+ /** Sort order: ascending or descending. */
147
+ sortOrder: 'asc' | 'desc';
148
+ };
149
+ }
150
+ /**
151
+ * Alias for paginated API response.
152
+ * Allows semantic naming like `PaginationResponse<User>` or `PaginationResponse<Post>`.
153
+ */
154
+ type PaginationResponse<T = any> = Pagination<T>;
155
+ /**
156
+ * Error response structure with additional metadata.
157
+ * Used for providing richer error information to clients.
158
+ */
159
+ interface ApiErrorResponse extends Omit<ApiResponse<never>, 'data'> {
160
+ /** Error always true for error responses */
161
+ error: true;
162
+ /** HTTP status code */
163
+ status: number;
164
+ /** Path to the resource that caused the error */
165
+ path: string;
166
+ /** Stack trace of the error (if available) */
167
+ stack?: string[];
168
+ }
169
+ /**
170
+ * Success response structure with strongly typed data.
171
+ * Used for providing successful responses to clients.
172
+ */
173
+ interface ApiSuccessResponse<T = any> extends ApiResponse<T> {
174
+ /** Error always false for success responses */
175
+ error: false;
176
+ /** HTTP status code (usually 200) */
177
+ status?: number;
178
+ }
179
+ /**
180
+ * Response structure for batch operations.
181
+ * Used when multiple operations are performed in a single request.
182
+ */
183
+ interface BatchResponse<T = any> {
184
+ /** Overall success/failure indicator */
185
+ success: boolean;
186
+ /** Total number of operations */
187
+ total: number;
188
+ /** Number of successful operations */
189
+ successful: number;
190
+ /** Number of failed operations */
191
+ failed: number;
192
+ /** Results of individual operations */
193
+ results: Array<{
194
+ /** Identifier for this operation */
195
+ id: string | number;
196
+ /** Success/failure indicator for this operation */
197
+ success: boolean;
198
+ /** Response data for this operation */
199
+ data?: T;
200
+ /** Error information if this operation failed */
201
+ error?: {
202
+ message: string;
203
+ code?: string;
204
+ };
205
+ }>;
206
+ }
207
+ /**
208
+ * Response structure for asynchronous operations.
209
+ * Used when the operation will complete in the future.
210
+ */
211
+ interface AsyncOperationResponse {
212
+ /** Always true for async operations */
213
+ async: true;
214
+ /** Job or task ID to check status later */
215
+ jobId: string;
216
+ /** Estimated completion time in seconds (if known) */
217
+ estimatedTime?: number;
218
+ /** URL to check status */
219
+ statusUrl: string;
220
+ }
221
+ /**
222
+ * Response structure for streaming operations.
223
+ * Used when data is returned as a stream rather than all at once.
224
+ */
225
+ interface StreamResponse {
226
+ /** Stream identifier */
227
+ streamId: string;
228
+ /** Stream type (e.g., 'json', 'binary') */
229
+ streamType: string;
230
+ /** Total size in bytes (if known) */
231
+ totalSize?: number;
232
+ /** Chunk size in bytes */
233
+ chunkSize: number;
234
+ }
235
+ /**
236
+ * Sort direction enumeration.
237
+ */
238
+ declare enum SortDirection {
239
+ /** Ascending sort order */
240
+ ASC = "asc",
241
+ /** Descending sort order */
242
+ DESC = "desc"
243
+ }
244
+ /**
245
+ * Pagination parameters for API requests.
246
+ */
247
+ interface PaginationParams {
248
+ /** Current page number (1-based index) */
249
+ page: number;
250
+ /** Number of records per page */
251
+ limit: number;
252
+ /** Field by which the data is sorted */
253
+ sortBy: string;
254
+ /** Sort order: ascending or descending */
255
+ sortOrder: SortDirection;
256
+ /** Optional search query */
257
+ search?: string;
258
+ }
259
+ /**
260
+ * Type that combines pagination parameters with additional data.
261
+ */
262
+ type WithPagination<T = {}> = PaginationParams & T;
263
+
264
+ export { SortDirection, extractFilterParams, extractPaginationParams, extractSortParams, getPaginationParams, parseBooleanParam, parseNumberParam };
265
+ export type { ApiErrorResponse, ApiResponse, ApiSuccessResponse, AsyncOperationResponse, BatchResponse, Pagination, PaginationParams, PaginationResponse, StreamResponse, ValidationOptions, ValidationResult, WithPagination };
package/request/index.mjs CHANGED
@@ -59,7 +59,7 @@ function parseNumberParam(value, options = {}) {
59
59
  };
60
60
  }
61
61
  const num = Number(value);
62
- if (isNaN(num)) {
62
+ if (Number.isNaN(num)) {
63
63
  if (throwOnError) throw new BadRequestException(errorMessage);
64
64
  return {
65
65
  isValid: false,
@@ -22,5 +22,321 @@
22
22
  * SOFTWARE.
23
23
  */
24
24
 
25
- export * from './response.utils';
26
- export * from '../types/api-response';
25
+ import { Request } from 'express';
26
+ import { ApiResponse as ApiResponse$1, ApiErrorResponse as ApiErrorResponse$1 } from '@catbee/utils/response';
27
+
28
+ /**
29
+ * Standard HTTP response wrapper for successful responses.
30
+ * Implements the `ApiResponse<T>` interface and sets default values.
31
+ *
32
+ * @typeParam T - The shape of the data returned in the response.
33
+ */
34
+ declare class SuccessResponse<T> implements ApiResponse$1<T> {
35
+ /** Message describing the result of the operation. */
36
+ message: string;
37
+ /** Whether the response is an error. Always false in success responses. */
38
+ error: boolean;
39
+ /** The payload returned from the API. */
40
+ data: T | null;
41
+ /** Timestamp when the response was generated, in ISO format. */
42
+ timestamp: string;
43
+ /** Unique identifier for this response, useful for request tracing. */
44
+ requestId: string;
45
+ /**
46
+ * Constructs a new success response.
47
+ *
48
+ * @param {string} message - Optional message to override the default.
49
+ * @param {T} [data] - Optional data payload.
50
+ */
51
+ constructor(message: string, data?: T);
52
+ }
53
+ /**
54
+ * Wrapper for error responses that extends the native `Error` object.
55
+ * Implements `ApiResponse` but omits the `data` field (which should not be present in errors).
56
+ */
57
+ declare class ErrorResponse extends Error implements Omit<ApiResponse$1<never>, 'data'> {
58
+ /** HTTP status code associated with the error (e.g., 404, 500). */
59
+ status: number;
60
+ /** Indicates that this is an error. Always true. */
61
+ error: boolean;
62
+ /** Timestamp when the error occurred, in ISO format. */
63
+ timestamp: string;
64
+ /** Unique identifier for this error instance. */
65
+ requestId: string;
66
+ /**
67
+ * Constructs a new error response.
68
+ *
69
+ * @param {string} message - The error message to display or log.
70
+ * @param {number} [status=500] - Optional HTTP status code (defaults to 500).
71
+ */
72
+ constructor(message: string, status?: number);
73
+ }
74
+ /**
75
+ * Response with paginated data extending the standard success response.
76
+ * Useful for APIs that return large collections of data.
77
+ *
78
+ * @typeParam T - The shape of each item in the paginated collection.
79
+ */
80
+ declare class PaginatedResponse<T> extends SuccessResponse<T[]> {
81
+ /** Total number of items across all pages */
82
+ total: number;
83
+ /** Current page number (1-based) */
84
+ page: number;
85
+ /** Number of items per page */
86
+ pageSize: number;
87
+ /** Total number of pages */
88
+ totalPages: number;
89
+ /** Whether there's a next page available */
90
+ hasNext: boolean;
91
+ /** Whether there's a previous page available */
92
+ hasPrevious: boolean;
93
+ /**
94
+ * Constructs a new paginated response.
95
+ *
96
+ * @param {T[]} items - The current page of items.
97
+ * @param {Object} pagination - Pagination information.
98
+ * @param {number} pagination.total - Total number of items across all pages.
99
+ * @param {number} pagination.page - Current page number (1-based).
100
+ * @param {number} pagination.pageSize - Number of items per page.
101
+ * @param {string} [message="Success"] - Optional custom message.
102
+ */
103
+ constructor(items: T[], pagination: {
104
+ total: number;
105
+ page: number;
106
+ pageSize: number;
107
+ }, message?: string);
108
+ }
109
+ /**
110
+ * Specialized response for operations that don't return data (HTTP 204).
111
+ */
112
+ declare class NoContentResponse extends SuccessResponse<null> {
113
+ /**
114
+ * Constructs a new no-content response.
115
+ *
116
+ * @param {string} [message="Operation completed successfully"] - Optional custom message.
117
+ */
118
+ constructor(message?: string);
119
+ }
120
+ /**
121
+ * Specialized response for redirects.
122
+ */
123
+ declare class RedirectResponse {
124
+ /** The URL to redirect to */
125
+ redirectUrl: string;
126
+ /** HTTP status code for the redirect (301, 302, 303, 307, 308) */
127
+ statusCode: number;
128
+ /** Whether the response is a redirect */
129
+ isRedirect: boolean;
130
+ /** Unique identifier for this response */
131
+ requestId: string;
132
+ /**
133
+ * Constructs a new redirect response.
134
+ *
135
+ * @param {string} url - The URL to redirect to.
136
+ * @param {number} [statusCode=302] - HTTP status code for the redirect.
137
+ */
138
+ constructor(url: string, statusCode?: number);
139
+ }
140
+ /**
141
+ * Creates a standard success response.
142
+ *
143
+ * @typeParam T - The shape of the data returned in the response.
144
+ * @param {T} data - The data to include in the response.
145
+ * @param {string} [message="Success"] - Optional custom message.
146
+ * @returns {SuccessResponse<T>} A properly formatted success response.
147
+ */
148
+ declare function createSuccessResponse<T>(data: T, message?: string): SuccessResponse<T>;
149
+ /**
150
+ * Creates a standard error response.
151
+ *
152
+ * @param {string} message - The error message.
153
+ * @param {number} [statusCode=500] - HTTP status code for the error.
154
+ * @returns {ErrorResponse} A properly formatted error response.
155
+ */
156
+ declare function createErrorResponse(message: string, statusCode?: number): ErrorResponse;
157
+ /**
158
+ * Creates a final error response with request information.
159
+ *
160
+ * @param req - The original request object.
161
+ * @param status - The HTTP status code.
162
+ * @param message - The error message.
163
+ * @param error - The original error object (optional).
164
+ * @param options - Additional options for the response (optional).
165
+ * @returns A properly formatted final error response.
166
+ */
167
+ declare function createFinalErrorResponse(req: Request, status: number, message: string, error?: any, options?: {
168
+ includeDetails?: boolean;
169
+ }): ApiErrorResponse$1;
170
+ /**
171
+ * Creates a paginated response from array data.
172
+ *
173
+ * @typeParam T - The shape of each item in the collection.
174
+ * @param {T[]} allItems - The complete array of items to paginate.
175
+ * @param {number} page - The requested page (1-based).
176
+ * @param {number} pageSize - The number of items per page.
177
+ * @param {string} [message="Success"] - Optional custom message.
178
+ * @returns {PaginatedResponse<T>} A properly formatted paginated response.
179
+ */
180
+ declare function createPaginatedResponse<T>(allItems: T[], page: number, pageSize: number, message?: string): PaginatedResponse<T>;
181
+ /**
182
+ * Adapter to convert API responses to Express.js response format.
183
+ *
184
+ * @param {any} res - Express response object.
185
+ * @param {SuccessResponse<any> | ErrorResponse | RedirectResponse} apiResponse - API response instance.
186
+ */
187
+ declare function sendResponse(res: any, apiResponse: SuccessResponse<any> | ErrorResponse | RedirectResponse): void;
188
+
189
+ /**
190
+ * Generic API response format.
191
+ * Used to wrap any successful or failed response from the server.
192
+ */
193
+ interface ApiResponse<T = any> {
194
+ /** Payload returned from the API. Can be any shape depending on the endpoint. */
195
+ data: T | null;
196
+ /** Indicates whether an error occurred (true = error, false = success). */
197
+ error: boolean;
198
+ /** Success message describing the result of the operation. */
199
+ message: string;
200
+ /** Unique request ID for traceability in logs (e.g., from a middleware). */
201
+ requestId: string;
202
+ /** ISO timestamp when the response was generated. */
203
+ timestamp: string;
204
+ }
205
+ /**
206
+ * Generic pagination structure used for paged lists (e.g., /users?page=1).
207
+ */
208
+ interface Pagination<T = any> {
209
+ /** List of records for the current page. */
210
+ content: T[];
211
+ /** Metadata about the pagination state. */
212
+ pagination: {
213
+ /** Total number of records across all pages. */
214
+ totalRecords: number;
215
+ /** Total number of pages available. */
216
+ totalPages: number;
217
+ /** Current page number (1-based index). */
218
+ page: number;
219
+ /** Number of records per page. */
220
+ limit: number;
221
+ /** Field by which the data is sorted. */
222
+ sortBy: string;
223
+ /** Sort order: ascending or descending. */
224
+ sortOrder: 'asc' | 'desc';
225
+ };
226
+ }
227
+ /**
228
+ * Alias for paginated API response.
229
+ * Allows semantic naming like `PaginationResponse<User>` or `PaginationResponse<Post>`.
230
+ */
231
+ type PaginationResponse<T = any> = Pagination<T>;
232
+ /**
233
+ * Error response structure with additional metadata.
234
+ * Used for providing richer error information to clients.
235
+ */
236
+ interface ApiErrorResponse extends Omit<ApiResponse<never>, 'data'> {
237
+ /** Error always true for error responses */
238
+ error: true;
239
+ /** HTTP status code */
240
+ status: number;
241
+ /** Path to the resource that caused the error */
242
+ path: string;
243
+ /** Stack trace of the error (if available) */
244
+ stack?: string[];
245
+ }
246
+ /**
247
+ * Success response structure with strongly typed data.
248
+ * Used for providing successful responses to clients.
249
+ */
250
+ interface ApiSuccessResponse<T = any> extends ApiResponse<T> {
251
+ /** Error always false for success responses */
252
+ error: false;
253
+ /** HTTP status code (usually 200) */
254
+ status?: number;
255
+ }
256
+ /**
257
+ * Response structure for batch operations.
258
+ * Used when multiple operations are performed in a single request.
259
+ */
260
+ interface BatchResponse<T = any> {
261
+ /** Overall success/failure indicator */
262
+ success: boolean;
263
+ /** Total number of operations */
264
+ total: number;
265
+ /** Number of successful operations */
266
+ successful: number;
267
+ /** Number of failed operations */
268
+ failed: number;
269
+ /** Results of individual operations */
270
+ results: Array<{
271
+ /** Identifier for this operation */
272
+ id: string | number;
273
+ /** Success/failure indicator for this operation */
274
+ success: boolean;
275
+ /** Response data for this operation */
276
+ data?: T;
277
+ /** Error information if this operation failed */
278
+ error?: {
279
+ message: string;
280
+ code?: string;
281
+ };
282
+ }>;
283
+ }
284
+ /**
285
+ * Response structure for asynchronous operations.
286
+ * Used when the operation will complete in the future.
287
+ */
288
+ interface AsyncOperationResponse {
289
+ /** Always true for async operations */
290
+ async: true;
291
+ /** Job or task ID to check status later */
292
+ jobId: string;
293
+ /** Estimated completion time in seconds (if known) */
294
+ estimatedTime?: number;
295
+ /** URL to check status */
296
+ statusUrl: string;
297
+ }
298
+ /**
299
+ * Response structure for streaming operations.
300
+ * Used when data is returned as a stream rather than all at once.
301
+ */
302
+ interface StreamResponse {
303
+ /** Stream identifier */
304
+ streamId: string;
305
+ /** Stream type (e.g., 'json', 'binary') */
306
+ streamType: string;
307
+ /** Total size in bytes (if known) */
308
+ totalSize?: number;
309
+ /** Chunk size in bytes */
310
+ chunkSize: number;
311
+ }
312
+ /**
313
+ * Sort direction enumeration.
314
+ */
315
+ declare enum SortDirection {
316
+ /** Ascending sort order */
317
+ ASC = "asc",
318
+ /** Descending sort order */
319
+ DESC = "desc"
320
+ }
321
+ /**
322
+ * Pagination parameters for API requests.
323
+ */
324
+ interface PaginationParams {
325
+ /** Current page number (1-based index) */
326
+ page: number;
327
+ /** Number of records per page */
328
+ limit: number;
329
+ /** Field by which the data is sorted */
330
+ sortBy: string;
331
+ /** Sort order: ascending or descending */
332
+ sortOrder: SortDirection;
333
+ /** Optional search query */
334
+ search?: string;
335
+ }
336
+ /**
337
+ * Type that combines pagination parameters with additional data.
338
+ */
339
+ type WithPagination<T = {}> = PaginationParams & T;
340
+
341
+ export { ErrorResponse, NoContentResponse, PaginatedResponse, RedirectResponse, SortDirection, SuccessResponse, createErrorResponse, createFinalErrorResponse, createPaginatedResponse, createSuccessResponse, sendResponse };
342
+ export type { ApiErrorResponse, ApiResponse, ApiSuccessResponse, AsyncOperationResponse, BatchResponse, Pagination, PaginationParams, PaginationResponse, StreamResponse, WithPagination };