@catbee/utils 2.0.0-next.0 → 2.0.0

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 (122) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +102 -52
  3. package/array/index.cjs +215 -74
  4. package/array/index.d.ts +345 -2
  5. package/array/index.mjs +201 -74
  6. package/async/index.cjs +116 -39
  7. package/async/index.d.ts +292 -2
  8. package/async/index.mjs +116 -40
  9. package/cache/index.cjs +2 -2
  10. package/cache/index.d.ts +156 -2
  11. package/cache/index.mjs +3 -3
  12. package/config/index.cjs +80 -66
  13. package/config/index.d.ts +65 -3
  14. package/config/index.mjs +77 -65
  15. package/context-store/index.cjs +2 -3
  16. package/context-store/index.d.ts +193 -2
  17. package/context-store/index.mjs +2 -3
  18. package/crypto/index.cjs +55 -5
  19. package/crypto/index.d.ts +225 -2
  20. package/crypto/index.mjs +52 -7
  21. package/date/index.cjs +676 -2
  22. package/date/index.d.ts +676 -2
  23. package/date/index.mjs +665 -3
  24. package/decorator/index.cjs +2172 -0
  25. package/{decorators/decorators.utils.d.ts → decorator/index.d.ts} +58 -54
  26. package/decorator/index.mjs +2131 -0
  27. package/{dir → directory}/index.cjs +5 -4
  28. package/{dir/dir.utils.d.ts → directory/index.d.ts} +24 -21
  29. package/{dir → directory}/index.mjs +5 -4
  30. package/env/index.cjs +100 -68
  31. package/env/index.d.ts +391 -2
  32. package/env/index.mjs +100 -68
  33. package/exception/index.cjs +1 -1
  34. package/exception/index.d.ts +233 -2
  35. package/exception/index.mjs +1 -1
  36. package/fs/index.cjs +71 -37
  37. package/fs/index.d.ts +206 -2
  38. package/fs/index.mjs +65 -35
  39. package/http-status-codes/index.cjs +1 -1
  40. package/http-status-codes/index.d.ts +268 -2
  41. package/http-status-codes/index.mjs +1 -1
  42. package/id/index.cjs +1 -1
  43. package/id/index.d.ts +38 -2
  44. package/id/index.mjs +1 -1
  45. package/index.cjs +13 -13
  46. package/index.d.ts +5 -5
  47. package/index.mjs +5 -5
  48. package/logger/index.cjs +13 -15
  49. package/logger/index.d.ts +190 -2
  50. package/logger/index.mjs +14 -16
  51. package/middleware/index.cjs +1 -1
  52. package/middleware/index.d.ts +104 -2
  53. package/middleware/index.mjs +1 -1
  54. package/object/index.cjs +379 -0
  55. package/{obj/obj.utils.d.ts → object/index.d.ts} +73 -33
  56. package/object/index.mjs +360 -0
  57. package/package.json +41 -23
  58. package/performance/index.cjs +4 -4
  59. package/performance/index.d.ts +139 -2
  60. package/performance/index.mjs +4 -4
  61. package/request/index.cjs +37 -25
  62. package/request/index.d.ts +242 -3
  63. package/request/index.mjs +37 -25
  64. package/response/index.cjs +1 -1
  65. package/response/index.d.ts +319 -3
  66. package/response/index.mjs +1 -1
  67. package/server/index.cjs +249 -146
  68. package/server/index.d.ts +866 -5
  69. package/server/index.mjs +248 -144
  70. package/stream/index.cjs +1 -1
  71. package/stream/index.d.ts +91 -2
  72. package/stream/index.mjs +1 -1
  73. package/string/index.cjs +34 -1
  74. package/string/index.d.ts +146 -2
  75. package/string/index.mjs +31 -2
  76. package/type/index.cjs +19 -2
  77. package/type/index.d.ts +144 -2
  78. package/type/index.mjs +17 -3
  79. package/types/index.cjs +1 -1
  80. package/types/index.d.ts +775 -5
  81. package/types/index.mjs +1 -1
  82. package/url/index.cjs +63 -5
  83. package/url/index.d.ts +200 -2
  84. package/url/index.mjs +59 -6
  85. package/{validate → validation}/index.cjs +91 -44
  86. package/{validate/validate.utils.d.ts → validation/index.d.ts} +33 -24
  87. package/{validate → validation}/index.mjs +87 -44
  88. package/array/array.utils.d.ts +0 -191
  89. package/async/async.utils.d.ts +0 -296
  90. package/cache/cache.utils.d.ts +0 -176
  91. package/config/config.d.ts +0 -57
  92. package/context-store/context-store.utils.d.ts +0 -212
  93. package/crypto/crypto.utils.d.ts +0 -183
  94. package/date/date.utils.d.ts +0 -190
  95. package/decorators/index.cjs +0 -913
  96. package/decorators/index.d.ts +0 -25
  97. package/decorators/index.mjs +0 -872
  98. package/dir/index.d.ts +0 -25
  99. package/env/env.utils.d.ts +0 -400
  100. package/exception/exception.utils.d.ts +0 -253
  101. package/fs/fs.utils.d.ts +0 -196
  102. package/http-status-codes/http-status-codes.d.ts +0 -289
  103. package/id/id.utils.d.ts +0 -59
  104. package/logger/logger.utils.d.ts +0 -210
  105. package/middleware/middleware.utils.d.ts +0 -123
  106. package/obj/index.cjs +0 -317
  107. package/obj/index.d.ts +0 -25
  108. package/obj/index.mjs +0 -301
  109. package/performance/performance.utils.d.ts +0 -159
  110. package/request/request.utils.d.ts +0 -109
  111. package/response/response.utils.d.ts +0 -186
  112. package/server/server.builder.d.ts +0 -531
  113. package/server/server.d.ts +0 -303
  114. package/stream/stream.utils.d.ts +0 -111
  115. package/string/string.utils.d.ts +0 -124
  116. package/type/type.utils.d.ts +0 -129
  117. package/types/api-response.d.ts +0 -175
  118. package/types/common.d.ts +0 -148
  119. package/types/config.d.ts +0 -88
  120. package/types/server.d.ts +0 -291
  121. package/url/url.utils.d.ts +0 -164
  122. package/validate/index.d.ts +0 -25
package/request/index.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -61,7 +61,7 @@ function parseNumberParam(value, options = {}) {
61
61
  };
62
62
  }
63
63
  const num = Number(value);
64
- if (isNaN(num)) {
64
+ if (Number.isNaN(num)) {
65
65
  if (throwOnError) throw new exception.BadRequestException(errorMessage);
66
66
  return {
67
67
  isValid: false,
@@ -143,38 +143,50 @@ function extractPaginationParams(query, defaultPage = 1, defaultLimit = 20, maxL
143
143
  };
144
144
  }
145
145
  __name(extractPaginationParams, "extractPaginationParams");
146
- function extractSortParams(query, allowedFields, defaultSort = {
146
+ var DEFAULT_SORT = {
147
147
  sortBy: "createdAt",
148
148
  sortOrder: "desc"
149
- }) {
150
- let sortBy = defaultSort.sortBy;
151
- let sortOrder = defaultSort.sortOrder;
152
- if (typeof query.sortBy === "string") {
153
- sortBy = query.sortBy;
154
- } else if (Array.isArray(query.sortBy)) {
155
- sortBy = query.sortBy[0];
156
- } else if (typeof query.sort === "string") {
157
- sortBy = query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
158
- sortOrder = query.sort.startsWith("-") ? "desc" : "asc";
159
- } else if (Array.isArray(query.sort)) {
160
- sortBy = query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
161
- sortOrder = query.sort[0].startsWith("-") ? "desc" : "asc";
162
- }
163
- if (typeof query.sortOrder === "string") {
164
- const order = query.sortOrder.toLowerCase();
165
- if (order === "asc" || order === "desc") {
166
- sortOrder = order;
167
- }
168
- }
169
- if (allowedFields.length && !allowedFields.includes(sortBy)) {
170
- sortBy = defaultSort.sortBy;
149
+ };
150
+ function extractSortParams(query, allowedFields, defaultSort = DEFAULT_SORT) {
151
+ const inferredSortBy = getSortByFromQuery(query, defaultSort);
152
+ let sortOrder = getSortOrderFromQuery(query, defaultSort);
153
+ const explicit = applyExplicitSortOrder(query.sortOrder);
154
+ if (explicit) {
155
+ sortOrder = explicit;
171
156
  }
157
+ const sortBy = validateSortField(inferredSortBy, allowedFields, defaultSort.sortBy);
172
158
  return {
173
159
  sortBy,
174
160
  sortOrder
175
161
  };
176
162
  }
177
163
  __name(extractSortParams, "extractSortParams");
164
+ function getSortByFromQuery(query, defaultSort) {
165
+ if (typeof query.sortBy === "string") return query.sortBy;
166
+ if (Array.isArray(query.sortBy)) return query.sortBy[0];
167
+ if (typeof query.sort === "string") return query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
168
+ if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
169
+ return defaultSort.sortBy;
170
+ }
171
+ __name(getSortByFromQuery, "getSortByFromQuery");
172
+ function getSortOrderFromQuery(query, defaultSort) {
173
+ if (typeof query.sort === "string") return query.sort.startsWith("-") ? "desc" : "asc";
174
+ if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? "desc" : "asc";
175
+ return defaultSort.sortOrder;
176
+ }
177
+ __name(getSortOrderFromQuery, "getSortOrderFromQuery");
178
+ function applyExplicitSortOrder(sortOrderParam) {
179
+ if (typeof sortOrderParam !== "string") return null;
180
+ const order = sortOrderParam.toLowerCase();
181
+ if (order === "asc" || order === "desc") return order;
182
+ return null;
183
+ }
184
+ __name(applyExplicitSortOrder, "applyExplicitSortOrder");
185
+ function validateSortField(sortBy, allowedFields, defaultSortBy) {
186
+ if (allowedFields.length && !allowedFields.includes(sortBy)) return defaultSortBy;
187
+ return sortBy;
188
+ }
189
+ __name(validateSortField, "validateSortField");
178
190
  function extractFilterParams(query, allowedFilters) {
179
191
  const filters = {};
180
192
  for (const field of allowedFilters) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -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
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal
@@ -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,
@@ -141,38 +141,50 @@ function extractPaginationParams(query, defaultPage = 1, defaultLimit = 20, maxL
141
141
  };
142
142
  }
143
143
  __name(extractPaginationParams, "extractPaginationParams");
144
- function extractSortParams(query, allowedFields, defaultSort = {
144
+ var DEFAULT_SORT = {
145
145
  sortBy: "createdAt",
146
146
  sortOrder: "desc"
147
- }) {
148
- let sortBy = defaultSort.sortBy;
149
- let sortOrder = defaultSort.sortOrder;
150
- if (typeof query.sortBy === "string") {
151
- sortBy = query.sortBy;
152
- } else if (Array.isArray(query.sortBy)) {
153
- sortBy = query.sortBy[0];
154
- } else if (typeof query.sort === "string") {
155
- sortBy = query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
156
- sortOrder = query.sort.startsWith("-") ? "desc" : "asc";
157
- } else if (Array.isArray(query.sort)) {
158
- sortBy = query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
159
- sortOrder = query.sort[0].startsWith("-") ? "desc" : "asc";
160
- }
161
- if (typeof query.sortOrder === "string") {
162
- const order = query.sortOrder.toLowerCase();
163
- if (order === "asc" || order === "desc") {
164
- sortOrder = order;
165
- }
166
- }
167
- if (allowedFields.length && !allowedFields.includes(sortBy)) {
168
- sortBy = defaultSort.sortBy;
147
+ };
148
+ function extractSortParams(query, allowedFields, defaultSort = DEFAULT_SORT) {
149
+ const inferredSortBy = getSortByFromQuery(query, defaultSort);
150
+ let sortOrder = getSortOrderFromQuery(query, defaultSort);
151
+ const explicit = applyExplicitSortOrder(query.sortOrder);
152
+ if (explicit) {
153
+ sortOrder = explicit;
169
154
  }
155
+ const sortBy = validateSortField(inferredSortBy, allowedFields, defaultSort.sortBy);
170
156
  return {
171
157
  sortBy,
172
158
  sortOrder
173
159
  };
174
160
  }
175
161
  __name(extractSortParams, "extractSortParams");
162
+ function getSortByFromQuery(query, defaultSort) {
163
+ if (typeof query.sortBy === "string") return query.sortBy;
164
+ if (Array.isArray(query.sortBy)) return query.sortBy[0];
165
+ if (typeof query.sort === "string") return query.sort.startsWith("-") ? query.sort.slice(1) : query.sort;
166
+ if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? query.sort[0].slice(1) : query.sort[0];
167
+ return defaultSort.sortBy;
168
+ }
169
+ __name(getSortByFromQuery, "getSortByFromQuery");
170
+ function getSortOrderFromQuery(query, defaultSort) {
171
+ if (typeof query.sort === "string") return query.sort.startsWith("-") ? "desc" : "asc";
172
+ if (Array.isArray(query.sort)) return query.sort[0].startsWith("-") ? "desc" : "asc";
173
+ return defaultSort.sortOrder;
174
+ }
175
+ __name(getSortOrderFromQuery, "getSortOrderFromQuery");
176
+ function applyExplicitSortOrder(sortOrderParam) {
177
+ if (typeof sortOrderParam !== "string") return null;
178
+ const order = sortOrderParam.toLowerCase();
179
+ if (order === "asc" || order === "desc") return order;
180
+ return null;
181
+ }
182
+ __name(applyExplicitSortOrder, "applyExplicitSortOrder");
183
+ function validateSortField(sortBy, allowedFields, defaultSortBy) {
184
+ if (allowedFields.length && !allowedFields.includes(sortBy)) return defaultSortBy;
185
+ return sortBy;
186
+ }
187
+ __name(validateSortField, "validateSortField");
176
188
  function extractFilterParams(query, allowedFilters) {
177
189
  const filters = {};
178
190
  for (const field of allowedFilters) {
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  * The MIT License
3
3
  *
4
- * Copyright (c) 2025 Catbee Technologies. https://catbee.in/license
4
+ * Copyright (c) 2026 Catbee Technologies. https://catbee.in/license
5
5
  *
6
6
  * Permission is hereby granted, free of charge, to any person obtaining a copy
7
7
  * of this software and associated documentation files (the "Software"), to deal