@orion-js/helpers 4.0.0-next.0 → 4.0.0-next.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,16 +1,17 @@
1
- // Generated by dts-bundle-generator v9.5.1
2
-
3
1
  /**
4
2
  * Creates a timeout with a promise
5
3
  */
6
4
  declare const _default: (time: number) => Promise<void>;
7
- declare function _default$1(object: any): string;
5
+
6
+ declare function export_default(object: any): string;
7
+
8
8
  /**
9
9
  * Returns a random ID
10
10
  * @param charsCount length of the ID
11
11
  * @param chars characters used to generate the ID
12
12
  */
13
- export function generateId(charsCount?: number, chars?: string): string;
13
+ declare function generateId(charsCount?: number, chars?: string): string;
14
+
14
15
  /**
15
16
  * Creates a map (object) from an array of items, using a specified property as the key.
16
17
  *
@@ -27,7 +28,8 @@ export function generateId(charsCount?: number, chars?: string): string;
27
28
  * // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }
28
29
  * createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')
29
30
  */
30
- export function createMap<T>(array: Array<T>, key?: string): Record<string, T>;
31
+ declare function createMap<T>(array: Array<T>, key?: string): Record<string, T>;
32
+
31
33
  /**
32
34
  * Creates a grouped map from an array of items, using a specified property as the key.
33
35
  *
@@ -49,20 +51,21 @@ export function createMap<T>(array: Array<T>, key?: string): Record<string, T>;
49
51
  * { id: 3, category: 'category1' }
50
52
  * ], 'category')
51
53
  */
52
- export function createMapArray<T>(array: Array<T>, key?: string): Record<string, Array<T>>;
54
+ declare function createMapArray<T>(array: Array<T>, key?: string): Record<string, Array<T>>;
55
+
53
56
  /**
54
57
  * Interface representing the standardized error information structure for Orion errors.
55
58
  * This is used by the getInfo method to provide consistent error reporting.
56
59
  */
57
- export interface OrionErrorInformation {
58
- /** The error code or identifier */
59
- error: string;
60
- /** Human-readable error message */
61
- message: string;
62
- /** Additional error metadata or context */
63
- extra: any;
64
- /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */
65
- type?: string;
60
+ interface OrionErrorInformation {
61
+ /** The error code or identifier */
62
+ error: string;
63
+ /** Human-readable error message */
64
+ message: string;
65
+ /** Additional error metadata or context */
66
+ extra: any;
67
+ /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */
68
+ type?: string;
66
69
  }
67
70
  /**
68
71
  * Base error class for all Orion-specific errors.
@@ -77,18 +80,19 @@ export interface OrionErrorInformation {
77
80
  * @property code - Error code for identifying the error type
78
81
  * @property extra - Additional error context or metadata
79
82
  */
80
- export declare class OrionError extends Error {
81
- isOrionError: boolean;
82
- isUserError: boolean;
83
- isPermissionsError: boolean;
84
- code: string;
85
- extra: any;
86
- /**
87
- * Returns a standardized representation of the error information.
88
- * @returns An object containing error details in a consistent format
89
- */
90
- getInfo: () => OrionErrorInformation;
83
+ declare class OrionError extends Error {
84
+ isOrionError: boolean;
85
+ isUserError: boolean;
86
+ isPermissionsError: boolean;
87
+ code: string;
88
+ extra: any;
89
+ /**
90
+ * Returns a standardized representation of the error information.
91
+ * @returns An object containing error details in a consistent format
92
+ */
93
+ getInfo: () => OrionErrorInformation;
91
94
  }
95
+
92
96
  /**
93
97
  * Error class for permission-related errors in the Orion framework.
94
98
  *
@@ -99,32 +103,33 @@ export declare class OrionError extends Error {
99
103
  *
100
104
  * @extends OrionError
101
105
  */
102
- export declare class PermissionsError extends OrionError {
103
- /**
104
- * Creates a new PermissionsError instance.
105
- *
106
- * @param permissionErrorType - Identifies the specific permission that was violated
107
- * (e.g., 'read', 'write', 'admin')
108
- * @param extra - Additional error context or metadata. Can include a custom message
109
- * via the message property.
110
- *
111
- * @example
112
- * // Basic usage
113
- * throw new PermissionsError('delete_document')
114
- *
115
- * @example
116
- * // With custom message
117
- * throw new PermissionsError('access_admin', { message: 'Admin access required' })
118
- *
119
- * @example
120
- * // With additional context
121
- * throw new PermissionsError('edit_user', {
122
- * userId: 'user123',
123
- * requiredRole: 'admin'
124
- * })
125
- */
126
- constructor(permissionErrorType: any, extra?: any);
106
+ declare class PermissionsError extends OrionError {
107
+ /**
108
+ * Creates a new PermissionsError instance.
109
+ *
110
+ * @param permissionErrorType - Identifies the specific permission that was violated
111
+ * (e.g., 'read', 'write', 'admin')
112
+ * @param extra - Additional error context or metadata. Can include a custom message
113
+ * via the message property.
114
+ *
115
+ * @example
116
+ * // Basic usage
117
+ * throw new PermissionsError('delete_document')
118
+ *
119
+ * @example
120
+ * // With custom message
121
+ * throw new PermissionsError('access_admin', { message: 'Admin access required' })
122
+ *
123
+ * @example
124
+ * // With additional context
125
+ * throw new PermissionsError('edit_user', {
126
+ * userId: 'user123',
127
+ * requiredRole: 'admin'
128
+ * })
129
+ */
130
+ constructor(permissionErrorType: any, extra?: any);
127
131
  }
132
+
128
133
  /**
129
134
  * Error class for user-facing errors in the Orion framework.
130
135
  *
@@ -134,29 +139,34 @@ export declare class PermissionsError extends OrionError {
134
139
  *
135
140
  * @extends OrionError
136
141
  */
137
- export declare class UserError extends OrionError {
138
- /**
139
- * Creates a new UserError instance.
140
- *
141
- * @param code - Error code identifier. If only one parameter is provided,
142
- * this will be used as the message and code will default to 'error'.
143
- * @param message - Human-readable error message. Optional if code is provided.
144
- * @param extra - Additional error context or metadata.
145
- *
146
- * @example
147
- * // Basic usage
148
- * throw new UserError('invalid_input', 'The provided email is invalid')
149
- *
150
- * @example
151
- * // Using only a message (code will be 'error')
152
- * throw new UserError('Input validation failed')
153
- *
154
- * @example
155
- * // With extra metadata
156
- * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
157
- */
158
- constructor(code: string, message?: string, extra?: any);
142
+ declare class UserError extends OrionError {
143
+ /**
144
+ * Creates a new UserError instance.
145
+ *
146
+ * @param code - Error code identifier. If only one parameter is provided,
147
+ * this will be used as the message and code will default to 'error'.
148
+ * @param message - Human-readable error message. Optional if code is provided.
149
+ * @param extra - Additional error context or metadata.
150
+ *
151
+ * @example
152
+ * // Basic usage
153
+ * throw new UserError('invalid_input', 'The provided email is invalid')
154
+ *
155
+ * @example
156
+ * // Using only a message (code will be 'error')
157
+ * throw new UserError('Input validation failed')
158
+ *
159
+ * @example
160
+ * // With extra metadata
161
+ * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
162
+ */
163
+ constructor(code: string, message?: string, extra?: any);
159
164
  }
165
+
166
+ /**
167
+ * @file Exports all error classes used in the Orion framework
168
+ */
169
+
160
170
  /**
161
171
  * Type guard to check if an error is an OrionError
162
172
  *
@@ -175,27 +185,29 @@ export declare class UserError extends OrionError {
175
185
  * }
176
186
  * }
177
187
  */
178
- export declare function isOrionError(error: any): error is OrionError;
188
+ declare function isOrionError(error: any): error is OrionError;
179
189
  /**
180
190
  * Type guard to check if an error is a UserError
181
191
  *
182
192
  * @param error - Any error object to test
183
193
  * @returns True if the error is a UserError instance
184
194
  */
185
- export declare function isUserError(error: any): error is UserError;
195
+ declare function isUserError(error: any): error is UserError;
186
196
  /**
187
197
  * Type guard to check if an error is a PermissionsError
188
198
  *
189
199
  * @param error - Any error object to test
190
200
  * @returns True if the error is a PermissionsError instance
191
201
  */
192
- export declare function isPermissionsError(error: any): error is PermissionsError;
202
+ declare function isPermissionsError(error: any): error is PermissionsError;
203
+
193
204
  /**
194
205
  * Compose `middleware` returning
195
206
  * a fully valid middleware comprised
196
207
  * of all those which are passed.
197
208
  */
198
- export declare function composeMiddlewares(middleware: any): (context: any, next?: any) => Promise<any>;
209
+ declare function composeMiddlewares(middleware: any): (context: any, next?: any) => Promise<any>;
210
+
199
211
  /**
200
212
  * Executes an asynchronous function with automatic retries on failure.
201
213
  *
@@ -218,9 +230,11 @@ export declare function composeMiddlewares(middleware: any): (context: any, next
218
230
  * 1000
219
231
  * );
220
232
  */
221
- export declare function executeWithRetries<TFunc extends () => Promise<any>>(fn: TFunc, retries: number, timeout: number): Promise<ReturnType<TFunc>>;
222
- export declare function generateUUID(): any;
223
- export declare function generateUUIDWithPrefix(prefix: string): string;
233
+ declare function executeWithRetries<TFunc extends () => Promise<any>>(fn: TFunc, retries: number, timeout: number): Promise<ReturnType<TFunc>>;
234
+
235
+ declare function generateUUID(): any;
236
+ declare function generateUUIDWithPrefix(prefix: string): string;
237
+
224
238
  /**
225
239
  * Removes diacritical marks (accents) from text without any other modifications.
226
240
  * This is the most basic normalization function that others build upon.
@@ -228,7 +242,7 @@ export declare function generateUUIDWithPrefix(prefix: string): string;
228
242
  * @param text - The input string to process
229
243
  * @returns String with accents removed but otherwise unchanged
230
244
  */
231
- export declare function removeAccentsOnly(text: string): string;
245
+ declare function removeAccentsOnly(text: string): string;
232
246
  /**
233
247
  * Normalizes text by removing diacritical marks (accents) and trimming whitespace.
234
248
  * Builds on removeAccentsOnly and adds whitespace trimming.
@@ -236,7 +250,7 @@ export declare function removeAccentsOnly(text: string): string;
236
250
  * @param text - The input string to normalize
237
251
  * @returns Normalized string with accents removed and whitespace trimmed
238
252
  */
239
- export declare function removeAccentsAndTrim(text: string): string;
253
+ declare function removeAccentsAndTrim(text: string): string;
240
254
  /**
241
255
  * Normalizes text for search purposes by:
242
256
  * - Removing diacritical marks (accents)
@@ -249,7 +263,7 @@ export declare function removeAccentsAndTrim(text: string): string;
249
263
  * @param text - The input string to normalize for search
250
264
  * @returns Search-optimized string in lowercase with accents removed
251
265
  */
252
- export declare function normalizeForSearch(text: string): string;
266
+ declare function normalizeForSearch(text: string): string;
253
267
  /**
254
268
  * Normalizes text for search purposes by:
255
269
  * - Removing diacritical marks (accents)
@@ -263,7 +277,7 @@ export declare function normalizeForSearch(text: string): string;
263
277
  * @param text - The input string to normalize for compact search
264
278
  * @returns Compact search-optimized string with no spaces
265
279
  */
266
- export declare function normalizeForCompactSearch(text: string): string;
280
+ declare function normalizeForCompactSearch(text: string): string;
267
281
  /**
268
282
  * Normalizes text for search token processing by:
269
283
  * - Removing diacritical marks (accents)
@@ -277,7 +291,7 @@ export declare function normalizeForCompactSearch(text: string): string;
277
291
  * @param text - The input string to normalize for tokenized search
278
292
  * @returns Search token string with only alphanumeric characters and spaces
279
293
  */
280
- export declare function normalizeForSearchToken(text: string): string;
294
+ declare function normalizeForSearchToken(text: string): string;
281
295
  /**
282
296
  * Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).
283
297
  * Performs the following transformations:
@@ -290,7 +304,8 @@ export declare function normalizeForSearchToken(text: string): string;
290
304
  * @param text - The input string to normalize for file key usage
291
305
  * @returns A storage-safe string suitable for use as a file key
292
306
  */
293
- export declare function normalizeForFileKey(text: string): string;
307
+ declare function normalizeForFileKey(text: string): string;
308
+
294
309
  /**
295
310
  * Generates an array of search tokens from input text and optional metadata.
296
311
  *
@@ -313,22 +328,22 @@ export declare function normalizeForFileKey(text: string): string;
313
328
  * // Returns ['hello', 'world', '_id:123']
314
329
  * getSearchTokens('Hello, World!', { id: '123' })
315
330
  */
316
- export declare function getSearchTokens(text: string[] | string, meta?: Record<string, string>): string[];
331
+ declare function getSearchTokens(text: string[] | string, meta?: Record<string, string>): string[];
317
332
  /**
318
333
  * Interface for parameters used in generating search queries from tokens.
319
334
  *
320
335
  * @property filter - Optional string to filter search results
321
336
  * @property [key: string] - Additional key-value pairs for metadata filtering
322
337
  */
323
- export interface SearchQueryForTokensParams {
324
- filter?: string;
325
- [key: string]: string;
338
+ interface SearchQueryForTokensParams {
339
+ filter?: string;
340
+ [key: string]: string;
326
341
  }
327
342
  /**
328
343
  * Options for customizing the search query generation behavior.
329
344
  * Currently empty but provided for future extensibility.
330
345
  */
331
- export type SearchQueryForTokensOptions = {};
346
+ type SearchQueryForTokensOptions = {};
332
347
  /**
333
348
  * Generates a MongoDB-compatible query object based on the provided parameters.
334
349
  *
@@ -349,14 +364,10 @@ export type SearchQueryForTokensOptions = {};
349
364
  * // Returns { $all: [/^search/, '_category:books'] }
350
365
  * getSearchQueryForTokens({ filter: 'search', category: 'books' })
351
366
  */
352
- export declare function getSearchQueryForTokens(params?: SearchQueryForTokensParams, _options?: SearchQueryForTokensOptions): {
353
- $all: (string | RegExp)[];
367
+ declare function getSearchQueryForTokens(params?: SearchQueryForTokensParams, _options?: SearchQueryForTokensOptions): {
368
+ $all: (string | RegExp)[];
354
369
  };
355
- export declare function shortenMongoId(string: string): string;
356
370
 
357
- export {
358
- _default as sleep,
359
- _default$1 as hashObject,
360
- };
371
+ declare function shortenMongoId(string: string): string;
361
372
 
362
- export {};
373
+ export { OrionError, type OrionErrorInformation, PermissionsError, type SearchQueryForTokensOptions, type SearchQueryForTokensParams, UserError, composeMiddlewares, createMap, createMapArray, executeWithRetries, generateId, generateUUID, generateUUIDWithPrefix, getSearchQueryForTokens, getSearchTokens, export_default as hashObject, isOrionError, isPermissionsError, isUserError, normalizeForCompactSearch, normalizeForFileKey, normalizeForSearch, normalizeForSearchToken, removeAccentsAndTrim, removeAccentsOnly, shortenMongoId, _default as sleep };