@orion-js/helpers 4.0.0-next.1 → 4.0.0-next.3
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/LICENSE +21 -0
- package/dist/index.cjs +209 -795
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +373 -0
- package/dist/index.d.ts +110 -99
- package/dist/index.js +159 -778
- package/dist/index.js.map +1 -0
- package/package.json +14 -11
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
-
|
|
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
|
-
|
|
353
|
-
|
|
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
|
-
|
|
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 };
|