@orion-js/helpers 4.0.0-next.3 → 4.0.0-next.4

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.cjs CHANGED
@@ -141,23 +141,23 @@ var OrionError = class extends Error {
141
141
  var PermissionsError = class extends OrionError {
142
142
  /**
143
143
  * Creates a new PermissionsError instance.
144
- *
144
+ *
145
145
  * @param permissionErrorType - Identifies the specific permission that was violated
146
146
  * (e.g., 'read', 'write', 'admin')
147
147
  * @param extra - Additional error context or metadata. Can include a custom message
148
148
  * via the message property.
149
- *
149
+ *
150
150
  * @example
151
151
  * // Basic usage
152
152
  * throw new PermissionsError('delete_document')
153
- *
153
+ *
154
154
  * @example
155
155
  * // With custom message
156
156
  * throw new PermissionsError('access_admin', { message: 'Admin access required' })
157
- *
157
+ *
158
158
  * @example
159
159
  * // With additional context
160
- * throw new PermissionsError('edit_user', {
160
+ * throw new PermissionsError('edit_user', {
161
161
  * userId: 'user123',
162
162
  * requiredRole: 'admin'
163
163
  * })
@@ -185,20 +185,20 @@ var PermissionsError = class extends OrionError {
185
185
  var UserError = class extends OrionError {
186
186
  /**
187
187
  * Creates a new UserError instance.
188
- *
188
+ *
189
189
  * @param code - Error code identifier. If only one parameter is provided,
190
190
  * this will be used as the message and code will default to 'error'.
191
191
  * @param message - Human-readable error message. Optional if code is provided.
192
192
  * @param extra - Additional error context or metadata.
193
- *
193
+ *
194
194
  * @example
195
195
  * // Basic usage
196
196
  * throw new UserError('invalid_input', 'The provided email is invalid')
197
- *
197
+ *
198
198
  * @example
199
199
  * // Using only a message (code will be 'error')
200
200
  * throw new UserError('Input validation failed')
201
- *
201
+ *
202
202
  * @example
203
203
  * // With extra metadata
204
204
  * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
@@ -282,61 +282,10 @@ function executeWithRetries(fn, retries, timeout) {
282
282
  });
283
283
  }
284
284
 
285
- // ../../node_modules/uuid/dist/esm-node/rng.js
286
- var import_crypto2 = __toESM(require("crypto"));
287
- var rnds8Pool = new Uint8Array(256);
288
- var poolPtr = rnds8Pool.length;
289
- function rng() {
290
- if (poolPtr > rnds8Pool.length - 16) {
291
- import_crypto2.default.randomFillSync(rnds8Pool);
292
- poolPtr = 0;
293
- }
294
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
295
- }
296
-
297
- // ../../node_modules/uuid/dist/esm-node/regex.js
298
- var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
299
-
300
- // ../../node_modules/uuid/dist/esm-node/validate.js
301
- function validate(uuid) {
302
- return typeof uuid === "string" && regex_default.test(uuid);
303
- }
304
- var validate_default = validate;
305
-
306
- // ../../node_modules/uuid/dist/esm-node/stringify.js
307
- var byteToHex = [];
308
- for (let i = 0; i < 256; ++i) {
309
- byteToHex.push((i + 256).toString(16).substr(1));
310
- }
311
- function stringify(arr, offset = 0) {
312
- const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
313
- if (!validate_default(uuid)) {
314
- throw TypeError("Stringified UUID is invalid");
315
- }
316
- return uuid;
317
- }
318
- var stringify_default = stringify;
319
-
320
- // ../../node_modules/uuid/dist/esm-node/v4.js
321
- function v4(options, buf, offset) {
322
- options = options || {};
323
- const rnds = options.random || (options.rng || rng)();
324
- rnds[6] = rnds[6] & 15 | 64;
325
- rnds[8] = rnds[8] & 63 | 128;
326
- if (buf) {
327
- offset = offset || 0;
328
- for (let i = 0; i < 16; ++i) {
329
- buf[offset + i] = rnds[i];
330
- }
331
- return buf;
332
- }
333
- return stringify_default(rnds);
334
- }
335
- var v4_default = v4;
336
-
337
285
  // src/generateUUID.ts
286
+ var import_uuid = require("uuid");
338
287
  function generateUUID() {
339
- return v4_default();
288
+ return (0, import_uuid.v4)();
340
289
  }
341
290
  function generateUUIDWithPrefix(prefix) {
342
291
  return `${prefix}-${generateUUID()}`;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/sleep.ts","../src/hashObject.ts","../src/generateId.ts","../src/createMap.ts","../src/createMapArray.ts","../src/Errors/OrionError.ts","../src/Errors/PermissionsError.ts","../src/Errors/UserError.ts","../src/Errors/index.ts","../src/composeMiddlewares.ts","../src/retries.ts","../../../node_modules/uuid/dist/esm-node/rng.js","../../../node_modules/uuid/dist/esm-node/regex.js","../../../node_modules/uuid/dist/esm-node/validate.js","../../../node_modules/uuid/dist/esm-node/stringify.js","../../../node_modules/uuid/dist/esm-node/v4.js","../src/generateUUID.ts","../src/normalize.ts","../src/searchTokens.ts","../src/shortenMongoId.ts"],"sourcesContent":["import sleep from './sleep'\nimport hashObject from './hashObject'\nimport generateId from './generateId'\nimport createMap from './createMap'\nimport createMapArray from './createMapArray'\n\n// Import all error-related exports from the Errors module\nimport {\n OrionError,\n PermissionsError,\n UserError,\n isOrionError,\n isUserError,\n isPermissionsError\n} from './Errors'\nimport type {OrionErrorInformation} from './Errors'\n\nexport * from './composeMiddlewares'\nexport * from './retries'\nexport * from './generateUUID'\nexport * from './normalize'\nexport * from './searchTokens'\nexport * from './shortenMongoId'\nexport {\n // Utility functions\n createMap,\n createMapArray,\n generateId,\n hashObject,\n sleep,\n\n // Error classes\n OrionError,\n PermissionsError,\n UserError,\n\n // Error type guards\n isOrionError,\n isUserError,\n isPermissionsError\n}\n\nexport type {OrionErrorInformation}\n","/**\n * Creates a timeout with a promise\n */\nexport default (time: number): Promise<void> => {\n return new Promise(resolve => setTimeout(resolve, time))\n}\n","import hash from 'object-hash'\n\nexport default function (object: any): string {\n return hash(object)\n}\n","import crypto from 'crypto'\n\nconst UNMISTAKABLE_CHARS = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz'\n\nconst hexString = function (digits) {\n var numBytes = Math.ceil(digits / 2)\n var bytes\n // Try to get cryptographically strong randomness. Fall back to\n // non-cryptographically strong if not available.\n try {\n bytes = crypto.randomBytes(numBytes)\n } catch (e) {\n // XXX should re-throw any error except insufficient entropy\n bytes = crypto.pseudoRandomBytes(numBytes)\n }\n var result = bytes.toString('hex')\n // If the number of digits is odd, we'll have generated an extra 4 bits\n // of randomness, so we need to trim the last digit.\n return result.substring(0, digits)\n}\n\nconst fraction = function () {\n var numerator = parseInt(hexString(8), 16)\n return numerator * 2.3283064365386963e-10 // 2^-32\n}\n\nconst choice = function (arrayOrString) {\n var index = Math.floor(fraction() * arrayOrString.length)\n if (typeof arrayOrString === 'string') return arrayOrString.substr(index, 1)\n else return arrayOrString[index]\n}\n\nconst randomString = function (charsCount, alphabet) {\n var digits = []\n for (var i = 0; i < charsCount; i++) {\n digits[i] = choice(alphabet)\n }\n return digits.join('')\n}\n\n/**\n * Returns a random ID\n * @param charsCount length of the ID\n * @param chars characters used to generate the ID\n */\nexport default function generateId(\n charsCount?: number,\n chars: string = UNMISTAKABLE_CHARS\n): string {\n if (!charsCount) {\n charsCount = 17\n }\n\n return randomString(charsCount, chars)\n}\n","/**\n * Creates a map (object) from an array of items, using a specified property as the key.\n * \n * This utility transforms an array of objects into a lookup object/dictionary where\n * each item in the array becomes a value in the map, indexed by the specified property.\n * If multiple items have the same key value, only the last one will be preserved.\n * \n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are the original items\n * \n * @example\n * // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }\n * createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')\n */\nexport default function createMap<T>(array: Array<T>, key: string = '_id'): Record<string, T> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = item\n }\n\n return map\n}\n","/**\n * Creates a grouped map from an array of items, using a specified property as the key.\n * \n * This utility transforms an array of objects into a lookup object/dictionary where\n * each value is an array of items sharing the same key value. Unlike createMap,\n * this function preserves all items with the same key by grouping them in arrays.\n * \n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a grouped map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are arrays of items\n * \n * @example\n * // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }], \n * // 'category2': [{ id: 2, category: 'category2' }] }\n * createMapArray([\n * { id: 1, category: 'category1' }, \n * { id: 2, category: 'category2' }, \n * { id: 3, category: 'category1' }\n * ], 'category')\n */\nexport default function createMapArray<T>(\n array: Array<T>,\n key: string = '_id'\n): Record<string, Array<T>> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = map[item[key]] || []\n map[item[key]].push(item)\n }\n\n return map\n}\n","/**\n * Interface representing the standardized error information structure for Orion errors.\n * This is used by the getInfo method to provide consistent error reporting.\n */\nexport interface OrionErrorInformation {\n /** The error code or identifier */\n error: string\n /** Human-readable error message */\n message: string\n /** Additional error metadata or context */\n extra: any\n /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */\n type?: string\n}\n\n/**\n * Base error class for all Orion-specific errors.\n * \n * This abstract class provides common properties and methods for all error types\n * used in the Orion framework. It's extended by more specific error classes\n * like UserError and PermissionsError.\n * \n * @property isOrionError - Flag indicating this is an Orion error (always true)\n * @property isUserError - Flag indicating if this is a user-facing error\n * @property isPermissionsError - Flag indicating if this is a permissions-related error\n * @property code - Error code for identifying the error type\n * @property extra - Additional error context or metadata\n */\nexport class OrionError extends Error {\n isOrionError = true\n\n isUserError: boolean\n isPermissionsError: boolean\n code: string\n extra: any\n\n /**\n * Returns a standardized representation of the error information.\n * @returns An object containing error details in a consistent format\n */\n getInfo: () => OrionErrorInformation\n}\n","import { OrionError } from './OrionError'\n\n/**\n * Error class for permission-related errors in the Orion framework.\n * \n * PermissionsError represents authorization failures where a user or client \n * attempts to perform an action they don't have permission to execute.\n * This is used to distinguish security/permissions errors from other types\n * of errors for proper error handling and user feedback.\n * \n * @extends OrionError\n */\nexport default class PermissionsError extends OrionError {\n /**\n * Creates a new PermissionsError instance.\n * \n * @param permissionErrorType - Identifies the specific permission that was violated\n * (e.g., 'read', 'write', 'admin')\n * @param extra - Additional error context or metadata. Can include a custom message\n * via the message property.\n * \n * @example\n * // Basic usage\n * throw new PermissionsError('delete_document')\n * \n * @example\n * // With custom message\n * throw new PermissionsError('access_admin', { message: 'Admin access required' })\n * \n * @example\n * // With additional context\n * throw new PermissionsError('edit_user', { \n * userId: 'user123',\n * requiredRole: 'admin'\n * })\n */\n constructor(permissionErrorType, extra: any = {}) {\n // Calling parent constructor of base Error class.\n const message =\n extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isPermissionsError = true\n this.code = 'PermissionsError'\n this.extra = extra\n\n this.getInfo = () => {\n return {\n ...extra,\n error: 'PermissionsError',\n message,\n type: permissionErrorType\n }\n }\n }\n}\n","import { OrionError } from './OrionError'\n\n/**\n * Error class for user-facing errors in the Orion framework.\n * \n * UserError is designed to represent errors that should be displayed to end users,\n * as opposed to system errors or unexpected failures. These errors typically represent\n * validation issues, business rule violations, or other expected error conditions.\n * \n * @extends OrionError\n */\nexport default class UserError extends OrionError {\n /**\n * Creates a new UserError instance.\n * \n * @param code - Error code identifier. If only one parameter is provided,\n * this will be used as the message and code will default to 'error'.\n * @param message - Human-readable error message. Optional if code is provided.\n * @param extra - Additional error context or metadata.\n * \n * @example\n * // Basic usage\n * throw new UserError('invalid_input', 'The provided email is invalid')\n * \n * @example\n * // Using only a message (code will be 'error')\n * throw new UserError('Input validation failed')\n * \n * @example\n * // With extra metadata\n * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })\n */\n constructor(code: string, message?: string, extra?: any) {\n if (!message && code) {\n message = code\n code = 'error'\n }\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isUserError = true\n this.code = code\n this.extra = extra\n\n this.getInfo = () => {\n return {\n error: code,\n message,\n extra\n }\n }\n }\n}\n","/**\n * @file Exports all error classes used in the Orion framework\n */\n\nimport {OrionError} from './OrionError'\nimport type {OrionErrorInformation} from './OrionError'\nimport PermissionsError from './PermissionsError'\nimport UserError from './UserError'\n\n/**\n * Re-export all error types for convenient importing\n */\nexport {OrionError, PermissionsError, UserError}\nexport type {OrionErrorInformation}\n\n/**\n * Type guard to check if an error is an OrionError\n *\n * @param error - Any error object to test\n * @returns True if the error is an OrionError instance\n *\n * @example\n * try {\n * // some code that might throw\n * } catch (error) {\n * if (isOrionError(error)) {\n * // Handle Orion-specific error\n * console.log(error.code, error.getInfo())\n * } else {\n * // Handle general error\n * }\n * }\n */\nexport function isOrionError(error: any): error is OrionError {\n return Boolean(error && typeof error === 'object' && error.isOrionError === true)\n}\n\n/**\n * Type guard to check if an error is a UserError\n *\n * @param error - Any error object to test\n * @returns True if the error is a UserError instance\n */\nexport function isUserError(error: any): error is UserError {\n return Boolean(\n error && typeof error === 'object' && error.isOrionError === true && error.isUserError === true,\n )\n}\n\n/**\n * Type guard to check if an error is a PermissionsError\n *\n * @param error - Any error object to test\n * @returns True if the error is a PermissionsError instance\n */\nexport function isPermissionsError(error: any): error is PermissionsError {\n return Boolean(\n error &&\n typeof error === 'object' &&\n error.isOrionError === true &&\n error.isPermissionsError === true,\n )\n}\n","// from https://github.com/koajs/compose/blob/master/index.js\n\n/**\n * Compose `middleware` returning\n * a fully valid middleware comprised\n * of all those which are passed.\n */\nexport function composeMiddlewares(middleware) {\n if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n for (const fn of middleware) {\n if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n }\n\n /**\n * @param {Object} context\n * @return {Promise}\n * @api public\n */\n\n return function (context, next?) {\n // last called middleware #\n let index = -1\n return dispatch(0)\n function dispatch(i) {\n if (i <= index) return Promise.reject(new Error('next() called multiple times'))\n index = i\n let fn = middleware[i]\n if (i === middleware.length) fn = next\n if (!fn) return Promise.resolve()\n try {\n return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n } catch (err) {\n return Promise.reject(err)\n }\n }\n }\n}\n","/**\n * Executes an asynchronous function with automatic retries on failure.\n * \n * This utility attempts to execute the provided function and automatically\n * retries if it fails, with a specified delay between attempts. It will\n * continue retrying until either the function succeeds or the maximum\n * number of retries is reached.\n * \n * @template TFunc Type of the function to execute (must return a Promise)\n * @param fn - The asynchronous function to execute\n * @param retries - The maximum number of retry attempts after the initial attempt\n * @param timeout - The delay in milliseconds between retry attempts\n * @returns A promise that resolves with the result of the function or rejects with the last error\n * \n * @example\n * // Retry an API call up to 3 times with 1 second between attempts\n * const result = await executeWithRetries(\n * () => fetchDataFromApi(),\n * 3,\n * 1000\n * );\n */\nexport function executeWithRetries<TFunc extends () => Promise<any>>(\n fn: TFunc,\n retries: number,\n timeout: number\n): Promise<ReturnType<TFunc>> {\n return new Promise((resolve, reject) => {\n const retry = async (retries: number) => {\n try {\n const result = await fn()\n resolve(result)\n } catch (error) {\n if (retries > 0) {\n setTimeout(() => retry(retries - 1), timeout)\n } else {\n reject(error)\n }\n }\n }\n retry(retries)\n })\n}\n","import crypto from 'crypto';\nconst rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate\n\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n crypto.randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n\n return rnds8Pool.slice(poolPtr, poolPtr += 16);\n}","export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).substr(1));\n}\n\nfunction stringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","import rng from './rng.js';\nimport stringify from './stringify.js';\n\nfunction v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return stringify(rnds);\n}\n\nexport default v4;","import { v4 as uuidv4 } from 'uuid'\n\nexport function generateUUID() {\n return uuidv4()\n}\n\nexport function generateUUIDWithPrefix(prefix: string) {\n return `${prefix}-${generateUUID()}`\n}\n","/**\n * Removes diacritical marks (accents) from text without any other modifications.\n * This is the most basic normalization function that others build upon.\n * \n * @param text - The input string to process\n * @returns String with accents removed but otherwise unchanged\n */\nexport function removeAccentsOnly(text: string) {\n if (!text) return ''\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: Removes diacritical marks (accents)\n return text.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '')\n}\n\n/**\n * Normalizes text by removing diacritical marks (accents) and trimming whitespace.\n * Builds on removeAccentsOnly and adds whitespace trimming.\n * \n * @param text - The input string to normalize\n * @returns Normalized string with accents removed and whitespace trimmed\n */\nexport function removeAccentsAndTrim(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text).trim()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * \n * Builds on removeAccentsAndTrim and adds lowercase conversion.\n * Useful for case-insensitive and accent-insensitive text searching.\n * \n * @param text - The input string to normalize for search\n * @returns Search-optimized string in lowercase with accents removed\n */\nexport function normalizeForSearch(text: string) {\n if (!text) return ''\n return removeAccentsAndTrim(text).toLowerCase()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Removing all spaces\n * \n * Builds on normalizeForSearch and removes all whitespace.\n * Useful for compact search indexes or when spaces should be ignored in searches.\n * \n * @param text - The input string to normalize for compact search\n * @returns Compact search-optimized string with no spaces\n */\nexport function normalizeForCompactSearch(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/\\s/g, '')\n}\n\n/**\n * Normalizes text for search token processing by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Replacing all non-alphanumeric characters with spaces\n * \n * Builds on normalizeForSearch and replaces non-alphanumeric characters with spaces.\n * Useful for tokenizing search terms where special characters should be treated as word separators.\n * \n * @param text - The input string to normalize for tokenized search\n * @returns Search token string with only alphanumeric characters and spaces\n */\nexport function normalizeForSearchToken(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/[^0-9a-z]/gi, ' ')\n}\n\n/**\n * Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).\n * Performs the following transformations:\n * - Removes accents/diacritical marks\n * - Replaces special characters with hyphens\n * - Ensures only alphanumeric characters, hyphens, periods, and underscores remain\n * - Replaces multiple consecutive hyphens with a single hyphen\n * - Removes leading/trailing hyphens\n * \n * @param text - The input string to normalize for file key usage\n * @returns A storage-safe string suitable for use as a file key\n */\nexport function normalizeForFileKey(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text)\n // Replace spaces and unwanted characters with hyphens\n .replace(/[^a-zA-Z0-9-._]/g, '-')\n // Replace multiple consecutive hyphens with single hyphen\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .trim()\n .replace(/^-+|-+$/g, '')\n}\n","import { normalizeForSearchToken } from './normalize'\n\n/**\n * Generates an array of search tokens from input text and optional metadata.\n * \n * This function processes text by:\n * 1. Converting it to an array of strings (if not already)\n * 2. Filtering out falsy values\n * 3. Normalizing each string (removing accents, special characters)\n * 4. Splitting by spaces to create individual tokens\n * 5. Optionally adding metadata tokens in the format \"_key:value\"\n * \n * @param text - String or array of strings to tokenize\n * @param meta - Optional metadata object where each key-value pair becomes a token\n * @returns Array of normalized search tokens\n * \n * @example\n * // Returns ['hello', 'world']\n * getSearchTokens('Hello, World!') \n * \n * @example\n * // Returns ['hello', 'world', '_id:123']\n * getSearchTokens('Hello, World!', { id: '123' })\n */\nexport function getSearchTokens(text: string[] | string, meta?: Record<string, string>) {\n const stringArray = Array.isArray(text) ? text : [text]\n const tokens = stringArray\n .filter(Boolean)\n .map(text => String(text))\n .flatMap(word => {\n return normalizeForSearchToken(word).split(' ').filter(Boolean)\n })\n\n if (meta) {\n for (const key in meta) {\n tokens.push(`_${key}:${meta[key]}`)\n }\n }\n\n return tokens\n}\n\n/**\n * Interface for parameters used in generating search queries from tokens.\n * \n * @property filter - Optional string to filter search results\n * @property [key: string] - Additional key-value pairs for metadata filtering\n */\nexport interface SearchQueryForTokensParams {\n filter?: string\n [key: string]: string\n}\n\n/**\n * Options for customizing the search query generation behavior.\n * Currently empty but provided for future extensibility.\n */\nexport type SearchQueryForTokensOptions = {}\n\n/**\n * Generates a MongoDB-compatible query object based on the provided parameters.\n * \n * This function:\n * 1. Processes any filter text into RegExp tokens for prefix matching\n * 2. Adds metadata filters based on additional properties in the params object\n * 3. Returns a query object with the $all operator for MongoDB queries\n * \n * @param params - Parameters for generating the search query\n * @param _options - Options for customizing search behavior (reserved for future use)\n * @returns A MongoDB-compatible query object with format { $all: [...tokens] }\n * \n * @example\n * // Returns { $all: [/^hello/, /^world/] }\n * getSearchQueryForTokens({ filter: 'Hello World' })\n * \n * @example\n * // Returns { $all: [/^search/, '_category:books'] }\n * getSearchQueryForTokens({ filter: 'search', category: 'books' })\n */\nexport function getSearchQueryForTokens(\n params: SearchQueryForTokensParams = {},\n _options: SearchQueryForTokensOptions = {},\n) {\n const searchTokens: (string | RegExp)[] = []\n\n if (params.filter) {\n const filterTokens = getSearchTokens(params.filter).map(token => new RegExp(`^${token}`))\n searchTokens.push(...filterTokens)\n }\n\n for (const key in params) {\n if (key === 'filter') continue\n if (!params[key]) continue\n searchTokens.push(`_${key}:${params[key]}`)\n }\n\n return { $all: searchTokens }\n}\n","function lastOfString(string: string, last: number) {\n return string.substring(string.length - last, string.length)\n}\n\nexport function shortenMongoId(string: string) {\n return lastOfString(string, 5).toUpperCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA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AM,EAAE,IAAI,WAAS,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;AACxF,iBAAa,KAAK,GAAG,YAAY;AAAA,EACnC;AAEA,aAAW,OAAO,QAAQ;AACxB,QAAI,QAAQ,SAAU;AACtB,QAAI,CAAC,OAAO,GAAG,EAAG;AAClB,iBAAa,KAAK,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,EAAE;AAAA,EAC5C;AAEA,SAAO,EAAE,MAAM,aAAa;AAC9B;;;ACjGA,SAAS,aAAa,QAAgB,MAAc;AAClD,SAAO,OAAO,UAAU,OAAO,SAAS,MAAM,OAAO,MAAM;AAC7D;AAEO,SAAS,eAAe,QAAgB;AAC7C,SAAO,aAAa,QAAQ,CAAC,EAAE,YAAY;AAC7C;","names":["hash","crypto","retries","import_crypto","crypto","text"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/sleep.ts","../src/hashObject.ts","../src/generateId.ts","../src/createMap.ts","../src/createMapArray.ts","../src/Errors/OrionError.ts","../src/Errors/PermissionsError.ts","../src/Errors/UserError.ts","../src/Errors/index.ts","../src/composeMiddlewares.ts","../src/retries.ts","../src/generateUUID.ts","../src/normalize.ts","../src/searchTokens.ts","../src/shortenMongoId.ts"],"sourcesContent":["import sleep from './sleep'\nimport hashObject from './hashObject'\nimport generateId from './generateId'\nimport createMap from './createMap'\nimport createMapArray from './createMapArray'\n\n// Import all error-related exports from the Errors module\nimport {\n OrionError,\n PermissionsError,\n UserError,\n isOrionError,\n isUserError,\n isPermissionsError,\n} from './Errors'\nimport type {OrionErrorInformation} from './Errors'\n\nexport * from './composeMiddlewares'\nexport * from './retries'\nexport * from './generateUUID'\nexport * from './normalize'\nexport * from './searchTokens'\nexport * from './shortenMongoId'\nexport {\n // Utility functions\n createMap,\n createMapArray,\n generateId,\n hashObject,\n sleep,\n // Error classes\n OrionError,\n PermissionsError,\n UserError,\n // Error type guards\n isOrionError,\n isUserError,\n isPermissionsError,\n}\n\nexport type {OrionErrorInformation}\n","/**\n * Creates a timeout with a promise\n */\nexport default (time: number): Promise<void> => {\n return new Promise(resolve => setTimeout(resolve, time))\n}\n","import hash from 'object-hash'\n\nexport default function (object: any): string {\n return hash(object)\n}\n","import crypto from 'crypto'\n\nconst UNMISTAKABLE_CHARS = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz'\n\nconst hexString = function (digits) {\n var numBytes = Math.ceil(digits / 2)\n var bytes\n // Try to get cryptographically strong randomness. Fall back to\n // non-cryptographically strong if not available.\n try {\n bytes = crypto.randomBytes(numBytes)\n } catch (e) {\n // XXX should re-throw any error except insufficient entropy\n bytes = crypto.pseudoRandomBytes(numBytes)\n }\n var result = bytes.toString('hex')\n // If the number of digits is odd, we'll have generated an extra 4 bits\n // of randomness, so we need to trim the last digit.\n return result.substring(0, digits)\n}\n\nconst fraction = function () {\n var numerator = parseInt(hexString(8), 16)\n return numerator * 2.3283064365386963e-10 // 2^-32\n}\n\nconst choice = function (arrayOrString) {\n var index = Math.floor(fraction() * arrayOrString.length)\n if (typeof arrayOrString === 'string') return arrayOrString.substr(index, 1)\n else return arrayOrString[index]\n}\n\nconst randomString = function (charsCount, alphabet) {\n var digits = []\n for (var i = 0; i < charsCount; i++) {\n digits[i] = choice(alphabet)\n }\n return digits.join('')\n}\n\n/**\n * Returns a random ID\n * @param charsCount length of the ID\n * @param chars characters used to generate the ID\n */\nexport default function generateId(\n charsCount?: number,\n chars: string = UNMISTAKABLE_CHARS,\n): string {\n if (!charsCount) {\n charsCount = 17\n }\n\n return randomString(charsCount, chars)\n}\n","/**\n * Creates a map (object) from an array of items, using a specified property as the key.\n *\n * This utility transforms an array of objects into a lookup object/dictionary where\n * each item in the array becomes a value in the map, indexed by the specified property.\n * If multiple items have the same key value, only the last one will be preserved.\n *\n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are the original items\n *\n * @example\n * // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }\n * createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')\n */\nexport default function createMap<T>(array: Array<T>, key: string = '_id'): Record<string, T> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = item\n }\n\n return map\n}\n","/**\n * Creates a grouped map from an array of items, using a specified property as the key.\n *\n * This utility transforms an array of objects into a lookup object/dictionary where\n * each value is an array of items sharing the same key value. Unlike createMap,\n * this function preserves all items with the same key by grouping them in arrays.\n *\n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a grouped map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are arrays of items\n *\n * @example\n * // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }],\n * // 'category2': [{ id: 2, category: 'category2' }] }\n * createMapArray([\n * { id: 1, category: 'category1' },\n * { id: 2, category: 'category2' },\n * { id: 3, category: 'category1' }\n * ], 'category')\n */\nexport default function createMapArray<T>(\n array: Array<T>,\n key: string = '_id',\n): Record<string, Array<T>> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = map[item[key]] || []\n map[item[key]].push(item)\n }\n\n return map\n}\n","/**\n * Interface representing the standardized error information structure for Orion errors.\n * This is used by the getInfo method to provide consistent error reporting.\n */\nexport interface OrionErrorInformation {\n /** The error code or identifier */\n error: string\n /** Human-readable error message */\n message: string\n /** Additional error metadata or context */\n extra: any\n /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */\n type?: string\n}\n\n/**\n * Base error class for all Orion-specific errors.\n *\n * This abstract class provides common properties and methods for all error types\n * used in the Orion framework. It's extended by more specific error classes\n * like UserError and PermissionsError.\n *\n * @property isOrionError - Flag indicating this is an Orion error (always true)\n * @property isUserError - Flag indicating if this is a user-facing error\n * @property isPermissionsError - Flag indicating if this is a permissions-related error\n * @property code - Error code for identifying the error type\n * @property extra - Additional error context or metadata\n */\nexport class OrionError extends Error {\n isOrionError = true\n\n isUserError: boolean\n isPermissionsError: boolean\n code: string\n extra: any\n\n /**\n * Returns a standardized representation of the error information.\n * @returns An object containing error details in a consistent format\n */\n getInfo: () => OrionErrorInformation\n}\n","import {OrionError} from './OrionError'\n\n/**\n * Error class for permission-related errors in the Orion framework.\n *\n * PermissionsError represents authorization failures where a user or client\n * attempts to perform an action they don't have permission to execute.\n * This is used to distinguish security/permissions errors from other types\n * of errors for proper error handling and user feedback.\n *\n * @extends OrionError\n */\nexport default class PermissionsError extends OrionError {\n /**\n * Creates a new PermissionsError instance.\n *\n * @param permissionErrorType - Identifies the specific permission that was violated\n * (e.g., 'read', 'write', 'admin')\n * @param extra - Additional error context or metadata. Can include a custom message\n * via the message property.\n *\n * @example\n * // Basic usage\n * throw new PermissionsError('delete_document')\n *\n * @example\n * // With custom message\n * throw new PermissionsError('access_admin', { message: 'Admin access required' })\n *\n * @example\n * // With additional context\n * throw new PermissionsError('edit_user', {\n * userId: 'user123',\n * requiredRole: 'admin'\n * })\n */\n constructor(permissionErrorType, extra: any = {}) {\n // Calling parent constructor of base Error class.\n const message =\n extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isPermissionsError = true\n this.code = 'PermissionsError'\n this.extra = extra\n\n this.getInfo = () => {\n return {\n ...extra,\n error: 'PermissionsError',\n message,\n type: permissionErrorType,\n }\n }\n }\n}\n","import {OrionError} from './OrionError'\n\n/**\n * Error class for user-facing errors in the Orion framework.\n *\n * UserError is designed to represent errors that should be displayed to end users,\n * as opposed to system errors or unexpected failures. These errors typically represent\n * validation issues, business rule violations, or other expected error conditions.\n *\n * @extends OrionError\n */\nexport default class UserError extends OrionError {\n /**\n * Creates a new UserError instance.\n *\n * @param code - Error code identifier. If only one parameter is provided,\n * this will be used as the message and code will default to 'error'.\n * @param message - Human-readable error message. Optional if code is provided.\n * @param extra - Additional error context or metadata.\n *\n * @example\n * // Basic usage\n * throw new UserError('invalid_input', 'The provided email is invalid')\n *\n * @example\n * // Using only a message (code will be 'error')\n * throw new UserError('Input validation failed')\n *\n * @example\n * // With extra metadata\n * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })\n */\n constructor(code: string, message?: string, extra?: any) {\n if (!message && code) {\n message = code\n code = 'error'\n }\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isUserError = true\n this.code = code\n this.extra = extra\n\n this.getInfo = () => {\n return {\n error: code,\n message,\n extra,\n }\n }\n }\n}\n","/**\n * @file Exports all error classes used in the Orion framework\n */\n\nimport {OrionError} from './OrionError'\nimport type {OrionErrorInformation} from './OrionError'\nimport PermissionsError from './PermissionsError'\nimport UserError from './UserError'\n\n/**\n * Re-export all error types for convenient importing\n */\nexport {OrionError, PermissionsError, UserError}\nexport type {OrionErrorInformation}\n\n/**\n * Type guard to check if an error is an OrionError\n *\n * @param error - Any error object to test\n * @returns True if the error is an OrionError instance\n *\n * @example\n * try {\n * // some code that might throw\n * } catch (error) {\n * if (isOrionError(error)) {\n * // Handle Orion-specific error\n * console.log(error.code, error.getInfo())\n * } else {\n * // Handle general error\n * }\n * }\n */\nexport function isOrionError(error: any): error is OrionError {\n return Boolean(error && typeof error === 'object' && error.isOrionError === true)\n}\n\n/**\n * Type guard to check if an error is a UserError\n *\n * @param error - Any error object to test\n * @returns True if the error is a UserError instance\n */\nexport function isUserError(error: any): error is UserError {\n return Boolean(\n error && typeof error === 'object' && error.isOrionError === true && error.isUserError === true,\n )\n}\n\n/**\n * Type guard to check if an error is a PermissionsError\n *\n * @param error - Any error object to test\n * @returns True if the error is a PermissionsError instance\n */\nexport function isPermissionsError(error: any): error is PermissionsError {\n return Boolean(\n error &&\n typeof error === 'object' &&\n error.isOrionError === true &&\n error.isPermissionsError === true,\n )\n}\n","// from https://github.com/koajs/compose/blob/master/index.js\n\n/**\n * Compose `middleware` returning\n * a fully valid middleware comprised\n * of all those which are passed.\n */\nexport function composeMiddlewares(middleware) {\n if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n for (const fn of middleware) {\n if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n }\n\n /**\n * @param {Object} context\n * @return {Promise}\n * @api public\n */\n\n return function (context, next?) {\n // last called middleware #\n let index = -1\n return dispatch(0)\n function dispatch(i) {\n if (i <= index) return Promise.reject(new Error('next() called multiple times'))\n index = i\n let fn = middleware[i]\n if (i === middleware.length) fn = next\n if (!fn) return Promise.resolve()\n try {\n return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n } catch (err) {\n return Promise.reject(err)\n }\n }\n }\n}\n","/**\n * Executes an asynchronous function with automatic retries on failure.\n *\n * This utility attempts to execute the provided function and automatically\n * retries if it fails, with a specified delay between attempts. It will\n * continue retrying until either the function succeeds or the maximum\n * number of retries is reached.\n *\n * @template TFunc Type of the function to execute (must return a Promise)\n * @param fn - The asynchronous function to execute\n * @param retries - The maximum number of retry attempts after the initial attempt\n * @param timeout - The delay in milliseconds between retry attempts\n * @returns A promise that resolves with the result of the function or rejects with the last error\n *\n * @example\n * // Retry an API call up to 3 times with 1 second between attempts\n * const result = await executeWithRetries(\n * () => fetchDataFromApi(),\n * 3,\n * 1000\n * );\n */\nexport function executeWithRetries<TFunc extends () => Promise<any>>(\n fn: TFunc,\n retries: number,\n timeout: number,\n): Promise<ReturnType<TFunc>> {\n return new Promise((resolve, reject) => {\n const retry = async (retries: number) => {\n try {\n const result = await fn()\n resolve(result)\n } catch (error) {\n if (retries > 0) {\n setTimeout(() => retry(retries - 1), timeout)\n } else {\n reject(error)\n }\n }\n }\n retry(retries)\n })\n}\n","import {v4 as uuidv4} from 'uuid'\n\nexport function generateUUID() {\n return uuidv4()\n}\n\nexport function generateUUIDWithPrefix(prefix: string) {\n return `${prefix}-${generateUUID()}`\n}\n","/**\n * Removes diacritical marks (accents) from text without any other modifications.\n * This is the most basic normalization function that others build upon.\n *\n * @param text - The input string to process\n * @returns String with accents removed but otherwise unchanged\n */\nexport function removeAccentsOnly(text: string) {\n if (!text) return ''\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: Removes diacritical marks (accents)\n return text.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '')\n}\n\n/**\n * Normalizes text by removing diacritical marks (accents) and trimming whitespace.\n * Builds on removeAccentsOnly and adds whitespace trimming.\n *\n * @param text - The input string to normalize\n * @returns Normalized string with accents removed and whitespace trimmed\n */\nexport function removeAccentsAndTrim(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text).trim()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n *\n * Builds on removeAccentsAndTrim and adds lowercase conversion.\n * Useful for case-insensitive and accent-insensitive text searching.\n *\n * @param text - The input string to normalize for search\n * @returns Search-optimized string in lowercase with accents removed\n */\nexport function normalizeForSearch(text: string) {\n if (!text) return ''\n return removeAccentsAndTrim(text).toLowerCase()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Removing all spaces\n *\n * Builds on normalizeForSearch and removes all whitespace.\n * Useful for compact search indexes or when spaces should be ignored in searches.\n *\n * @param text - The input string to normalize for compact search\n * @returns Compact search-optimized string with no spaces\n */\nexport function normalizeForCompactSearch(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/\\s/g, '')\n}\n\n/**\n * Normalizes text for search token processing by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Replacing all non-alphanumeric characters with spaces\n *\n * Builds on normalizeForSearch and replaces non-alphanumeric characters with spaces.\n * Useful for tokenizing search terms where special characters should be treated as word separators.\n *\n * @param text - The input string to normalize for tokenized search\n * @returns Search token string with only alphanumeric characters and spaces\n */\nexport function normalizeForSearchToken(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/[^0-9a-z]/gi, ' ')\n}\n\n/**\n * Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).\n * Performs the following transformations:\n * - Removes accents/diacritical marks\n * - Replaces special characters with hyphens\n * - Ensures only alphanumeric characters, hyphens, periods, and underscores remain\n * - Replaces multiple consecutive hyphens with a single hyphen\n * - Removes leading/trailing hyphens\n *\n * @param text - The input string to normalize for file key usage\n * @returns A storage-safe string suitable for use as a file key\n */\nexport function normalizeForFileKey(text: string) {\n if (!text) return ''\n return (\n removeAccentsOnly(text)\n // Replace spaces and unwanted characters with hyphens\n .replace(/[^a-zA-Z0-9-._]/g, '-')\n // Replace multiple consecutive hyphens with single hyphen\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .trim()\n .replace(/^-+|-+$/g, '')\n )\n}\n","import {normalizeForSearchToken} from './normalize'\n\n/**\n * Generates an array of search tokens from input text and optional metadata.\n *\n * This function processes text by:\n * 1. Converting it to an array of strings (if not already)\n * 2. Filtering out falsy values\n * 3. Normalizing each string (removing accents, special characters)\n * 4. Splitting by spaces to create individual tokens\n * 5. Optionally adding metadata tokens in the format \"_key:value\"\n *\n * @param text - String or array of strings to tokenize\n * @param meta - Optional metadata object where each key-value pair becomes a token\n * @returns Array of normalized search tokens\n *\n * @example\n * // Returns ['hello', 'world']\n * getSearchTokens('Hello, World!')\n *\n * @example\n * // Returns ['hello', 'world', '_id:123']\n * getSearchTokens('Hello, World!', { id: '123' })\n */\nexport function getSearchTokens(text: string[] | string, meta?: Record<string, string>) {\n const stringArray = Array.isArray(text) ? text : [text]\n const tokens = stringArray\n .filter(Boolean)\n .map(text => String(text))\n .flatMap(word => {\n return normalizeForSearchToken(word).split(' ').filter(Boolean)\n })\n\n if (meta) {\n for (const key in meta) {\n tokens.push(`_${key}:${meta[key]}`)\n }\n }\n\n return tokens\n}\n\n/**\n * Interface for parameters used in generating search queries from tokens.\n *\n * @property filter - Optional string to filter search results\n * @property [key: string] - Additional key-value pairs for metadata filtering\n */\nexport interface SearchQueryForTokensParams {\n filter?: string\n [key: string]: string\n}\n\n/**\n * Options for customizing the search query generation behavior.\n * Currently empty but provided for future extensibility.\n */\nexport type SearchQueryForTokensOptions = {}\n\n/**\n * Generates a MongoDB-compatible query object based on the provided parameters.\n *\n * This function:\n * 1. Processes any filter text into RegExp tokens for prefix matching\n * 2. Adds metadata filters based on additional properties in the params object\n * 3. Returns a query object with the $all operator for MongoDB queries\n *\n * @param params - Parameters for generating the search query\n * @param _options - Options for customizing search behavior (reserved for future use)\n * @returns A MongoDB-compatible query object with format { $all: [...tokens] }\n *\n * @example\n * // Returns { $all: [/^hello/, /^world/] }\n * getSearchQueryForTokens({ filter: 'Hello World' })\n *\n * @example\n * // Returns { $all: [/^search/, '_category:books'] }\n * getSearchQueryForTokens({ filter: 'search', category: 'books' })\n */\nexport function getSearchQueryForTokens(\n params: SearchQueryForTokensParams = {},\n _options: SearchQueryForTokensOptions = {},\n) {\n const searchTokens: (string | RegExp)[] = []\n\n if (params.filter) {\n const filterTokens = getSearchTokens(params.filter).map(token => new RegExp(`^${token}`))\n searchTokens.push(...filterTokens)\n }\n\n for (const key in params) {\n if (key === 'filter') continue\n if (!params[key]) continue\n searchTokens.push(`_${key}:${params[key]}`)\n }\n\n return {$all: searchTokens}\n}\n","function lastOfString(string: string, last: number) {\n return string.substring(string.length - last, string.length)\n}\n\nexport function shortenMongoId(string: string) {\n return lastOfString(string, 5).toUpperCase()\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGA,IAAO,gBAAQ,CAAC,SAAgC;AAC9C,SAAO,IAAI,QAAQ,aAAW,WAAW,SAAS,IAAI,CAAC;AACzD;;;ACLA,yBAAiB;AAEF,SAAR,mBAAkB,QAAqB;AAC5C,aAAO,mBAAAA,S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,OAAO,OAAO,EACd,IAAI,CAAAC,UAAQ,OAAOA,KAAI,CAAC,EACxB,QAAQ,UAAQ;AACf,WAAO,wBAAwB,IAAI,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAChE,CAAC;AAEH,MAAI,MAAM;AACR,eAAW,OAAO,MAAM;AACtB,aAAO,KAAK,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC,EAAE;AAAA,IACpC;AAAA,EACF;AAEA,SAAO;AACT;AAuCO,SAAS,wBACd,SAAqC,CAAC,GACtC,WAAwC,CAAC,GACzC;AACA,QAAM,eAAoC,CAAC;AAE3C,MAAI,OAAO,QAAQ;AACjB,UAAM,eAAe,gBAAgB,OAAO,MAAM,EAAE,IAAI,WAAS,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;AACxF,iBAAa,KAAK,GAAG,YAAY;AAAA,EACnC;AAEA,aAAW,OAAO,QAAQ;AACxB,QAAI,QAAQ,SAAU;AACtB,QAAI,CAAC,OAAO,GAAG,EAAG;AAClB,iBAAa,KAAK,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,EAAE;AAAA,EAC5C;AAEA,SAAO,EAAC,MAAM,aAAY;AAC5B;;;ACjGA,SAAS,aAAa,QAAgB,MAAc;AAClD,SAAO,OAAO,UAAU,OAAO,SAAS,MAAM,OAAO,MAAM;AAC7D;AAEO,SAAS,eAAe,QAAgB;AAC7C,SAAO,aAAa,QAAQ,CAAC,EAAE,YAAY;AAC7C;","names":["hash","crypto","retries","uuidv4","text"]}
package/dist/index.d.cts CHANGED
@@ -232,7 +232,7 @@ declare function composeMiddlewares(middleware: any): (context: any, next?: any)
232
232
  */
233
233
  declare function executeWithRetries<TFunc extends () => Promise<any>>(fn: TFunc, retries: number, timeout: number): Promise<ReturnType<TFunc>>;
234
234
 
235
- declare function generateUUID(): any;
235
+ declare function generateUUID(): string;
236
236
  declare function generateUUIDWithPrefix(prefix: string): string;
237
237
 
238
238
  /**
package/dist/index.d.ts CHANGED
@@ -232,7 +232,7 @@ declare function composeMiddlewares(middleware: any): (context: any, next?: any)
232
232
  */
233
233
  declare function executeWithRetries<TFunc extends () => Promise<any>>(fn: TFunc, retries: number, timeout: number): Promise<ReturnType<TFunc>>;
234
234
 
235
- declare function generateUUID(): any;
235
+ declare function generateUUID(): string;
236
236
  declare function generateUUIDWithPrefix(prefix: string): string;
237
237
 
238
238
  /**
package/dist/index.js CHANGED
@@ -83,23 +83,23 @@ var OrionError = class extends Error {
83
83
  var PermissionsError = class extends OrionError {
84
84
  /**
85
85
  * Creates a new PermissionsError instance.
86
- *
86
+ *
87
87
  * @param permissionErrorType - Identifies the specific permission that was violated
88
88
  * (e.g., 'read', 'write', 'admin')
89
89
  * @param extra - Additional error context or metadata. Can include a custom message
90
90
  * via the message property.
91
- *
91
+ *
92
92
  * @example
93
93
  * // Basic usage
94
94
  * throw new PermissionsError('delete_document')
95
- *
95
+ *
96
96
  * @example
97
97
  * // With custom message
98
98
  * throw new PermissionsError('access_admin', { message: 'Admin access required' })
99
- *
99
+ *
100
100
  * @example
101
101
  * // With additional context
102
- * throw new PermissionsError('edit_user', {
102
+ * throw new PermissionsError('edit_user', {
103
103
  * userId: 'user123',
104
104
  * requiredRole: 'admin'
105
105
  * })
@@ -127,20 +127,20 @@ var PermissionsError = class extends OrionError {
127
127
  var UserError = class extends OrionError {
128
128
  /**
129
129
  * Creates a new UserError instance.
130
- *
130
+ *
131
131
  * @param code - Error code identifier. If only one parameter is provided,
132
132
  * this will be used as the message and code will default to 'error'.
133
133
  * @param message - Human-readable error message. Optional if code is provided.
134
134
  * @param extra - Additional error context or metadata.
135
- *
135
+ *
136
136
  * @example
137
137
  * // Basic usage
138
138
  * throw new UserError('invalid_input', 'The provided email is invalid')
139
- *
139
+ *
140
140
  * @example
141
141
  * // Using only a message (code will be 'error')
142
142
  * throw new UserError('Input validation failed')
143
- *
143
+ *
144
144
  * @example
145
145
  * // With extra metadata
146
146
  * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })
@@ -224,61 +224,10 @@ function executeWithRetries(fn, retries, timeout) {
224
224
  });
225
225
  }
226
226
 
227
- // ../../node_modules/uuid/dist/esm-node/rng.js
228
- import crypto2 from "crypto";
229
- var rnds8Pool = new Uint8Array(256);
230
- var poolPtr = rnds8Pool.length;
231
- function rng() {
232
- if (poolPtr > rnds8Pool.length - 16) {
233
- crypto2.randomFillSync(rnds8Pool);
234
- poolPtr = 0;
235
- }
236
- return rnds8Pool.slice(poolPtr, poolPtr += 16);
237
- }
238
-
239
- // ../../node_modules/uuid/dist/esm-node/regex.js
240
- var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
241
-
242
- // ../../node_modules/uuid/dist/esm-node/validate.js
243
- function validate(uuid) {
244
- return typeof uuid === "string" && regex_default.test(uuid);
245
- }
246
- var validate_default = validate;
247
-
248
- // ../../node_modules/uuid/dist/esm-node/stringify.js
249
- var byteToHex = [];
250
- for (let i = 0; i < 256; ++i) {
251
- byteToHex.push((i + 256).toString(16).substr(1));
252
- }
253
- function stringify(arr, offset = 0) {
254
- const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase();
255
- if (!validate_default(uuid)) {
256
- throw TypeError("Stringified UUID is invalid");
257
- }
258
- return uuid;
259
- }
260
- var stringify_default = stringify;
261
-
262
- // ../../node_modules/uuid/dist/esm-node/v4.js
263
- function v4(options, buf, offset) {
264
- options = options || {};
265
- const rnds = options.random || (options.rng || rng)();
266
- rnds[6] = rnds[6] & 15 | 64;
267
- rnds[8] = rnds[8] & 63 | 128;
268
- if (buf) {
269
- offset = offset || 0;
270
- for (let i = 0; i < 16; ++i) {
271
- buf[offset + i] = rnds[i];
272
- }
273
- return buf;
274
- }
275
- return stringify_default(rnds);
276
- }
277
- var v4_default = v4;
278
-
279
227
  // src/generateUUID.ts
228
+ import { v4 as uuidv4 } from "uuid";
280
229
  function generateUUID() {
281
- return v4_default();
230
+ return uuidv4();
282
231
  }
283
232
  function generateUUIDWithPrefix(prefix) {
284
233
  return `${prefix}-${generateUUID()}`;
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/sleep.ts","../src/hashObject.ts","../src/generateId.ts","../src/createMap.ts","../src/createMapArray.ts","../src/Errors/OrionError.ts","../src/Errors/PermissionsError.ts","../src/Errors/UserError.ts","../src/Errors/index.ts","../src/composeMiddlewares.ts","../src/retries.ts","../../../node_modules/uuid/dist/esm-node/rng.js","../../../node_modules/uuid/dist/esm-node/regex.js","../../../node_modules/uuid/dist/esm-node/validate.js","../../../node_modules/uuid/dist/esm-node/stringify.js","../../../node_modules/uuid/dist/esm-node/v4.js","../src/generateUUID.ts","../src/normalize.ts","../src/searchTokens.ts","../src/shortenMongoId.ts"],"sourcesContent":["/**\n * Creates a timeout with a promise\n */\nexport default (time: number): Promise<void> => {\n return new Promise(resolve => setTimeout(resolve, time))\n}\n","import hash from 'object-hash'\n\nexport default function (object: any): string {\n return hash(object)\n}\n","import crypto from 'crypto'\n\nconst UNMISTAKABLE_CHARS = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz'\n\nconst hexString = function (digits) {\n var numBytes = Math.ceil(digits / 2)\n var bytes\n // Try to get cryptographically strong randomness. Fall back to\n // non-cryptographically strong if not available.\n try {\n bytes = crypto.randomBytes(numBytes)\n } catch (e) {\n // XXX should re-throw any error except insufficient entropy\n bytes = crypto.pseudoRandomBytes(numBytes)\n }\n var result = bytes.toString('hex')\n // If the number of digits is odd, we'll have generated an extra 4 bits\n // of randomness, so we need to trim the last digit.\n return result.substring(0, digits)\n}\n\nconst fraction = function () {\n var numerator = parseInt(hexString(8), 16)\n return numerator * 2.3283064365386963e-10 // 2^-32\n}\n\nconst choice = function (arrayOrString) {\n var index = Math.floor(fraction() * arrayOrString.length)\n if (typeof arrayOrString === 'string') return arrayOrString.substr(index, 1)\n else return arrayOrString[index]\n}\n\nconst randomString = function (charsCount, alphabet) {\n var digits = []\n for (var i = 0; i < charsCount; i++) {\n digits[i] = choice(alphabet)\n }\n return digits.join('')\n}\n\n/**\n * Returns a random ID\n * @param charsCount length of the ID\n * @param chars characters used to generate the ID\n */\nexport default function generateId(\n charsCount?: number,\n chars: string = UNMISTAKABLE_CHARS\n): string {\n if (!charsCount) {\n charsCount = 17\n }\n\n return randomString(charsCount, chars)\n}\n","/**\n * Creates a map (object) from an array of items, using a specified property as the key.\n * \n * This utility transforms an array of objects into a lookup object/dictionary where\n * each item in the array becomes a value in the map, indexed by the specified property.\n * If multiple items have the same key value, only the last one will be preserved.\n * \n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are the original items\n * \n * @example\n * // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }\n * createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')\n */\nexport default function createMap<T>(array: Array<T>, key: string = '_id'): Record<string, T> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = item\n }\n\n return map\n}\n","/**\n * Creates a grouped map from an array of items, using a specified property as the key.\n * \n * This utility transforms an array of objects into a lookup object/dictionary where\n * each value is an array of items sharing the same key value. Unlike createMap,\n * this function preserves all items with the same key by grouping them in arrays.\n * \n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a grouped map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are arrays of items\n * \n * @example\n * // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }], \n * // 'category2': [{ id: 2, category: 'category2' }] }\n * createMapArray([\n * { id: 1, category: 'category1' }, \n * { id: 2, category: 'category2' }, \n * { id: 3, category: 'category1' }\n * ], 'category')\n */\nexport default function createMapArray<T>(\n array: Array<T>,\n key: string = '_id'\n): Record<string, Array<T>> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = map[item[key]] || []\n map[item[key]].push(item)\n }\n\n return map\n}\n","/**\n * Interface representing the standardized error information structure for Orion errors.\n * This is used by the getInfo method to provide consistent error reporting.\n */\nexport interface OrionErrorInformation {\n /** The error code or identifier */\n error: string\n /** Human-readable error message */\n message: string\n /** Additional error metadata or context */\n extra: any\n /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */\n type?: string\n}\n\n/**\n * Base error class for all Orion-specific errors.\n * \n * This abstract class provides common properties and methods for all error types\n * used in the Orion framework. It's extended by more specific error classes\n * like UserError and PermissionsError.\n * \n * @property isOrionError - Flag indicating this is an Orion error (always true)\n * @property isUserError - Flag indicating if this is a user-facing error\n * @property isPermissionsError - Flag indicating if this is a permissions-related error\n * @property code - Error code for identifying the error type\n * @property extra - Additional error context or metadata\n */\nexport class OrionError extends Error {\n isOrionError = true\n\n isUserError: boolean\n isPermissionsError: boolean\n code: string\n extra: any\n\n /**\n * Returns a standardized representation of the error information.\n * @returns An object containing error details in a consistent format\n */\n getInfo: () => OrionErrorInformation\n}\n","import { OrionError } from './OrionError'\n\n/**\n * Error class for permission-related errors in the Orion framework.\n * \n * PermissionsError represents authorization failures where a user or client \n * attempts to perform an action they don't have permission to execute.\n * This is used to distinguish security/permissions errors from other types\n * of errors for proper error handling and user feedback.\n * \n * @extends OrionError\n */\nexport default class PermissionsError extends OrionError {\n /**\n * Creates a new PermissionsError instance.\n * \n * @param permissionErrorType - Identifies the specific permission that was violated\n * (e.g., 'read', 'write', 'admin')\n * @param extra - Additional error context or metadata. Can include a custom message\n * via the message property.\n * \n * @example\n * // Basic usage\n * throw new PermissionsError('delete_document')\n * \n * @example\n * // With custom message\n * throw new PermissionsError('access_admin', { message: 'Admin access required' })\n * \n * @example\n * // With additional context\n * throw new PermissionsError('edit_user', { \n * userId: 'user123',\n * requiredRole: 'admin'\n * })\n */\n constructor(permissionErrorType, extra: any = {}) {\n // Calling parent constructor of base Error class.\n const message =\n extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isPermissionsError = true\n this.code = 'PermissionsError'\n this.extra = extra\n\n this.getInfo = () => {\n return {\n ...extra,\n error: 'PermissionsError',\n message,\n type: permissionErrorType\n }\n }\n }\n}\n","import { OrionError } from './OrionError'\n\n/**\n * Error class for user-facing errors in the Orion framework.\n * \n * UserError is designed to represent errors that should be displayed to end users,\n * as opposed to system errors or unexpected failures. These errors typically represent\n * validation issues, business rule violations, or other expected error conditions.\n * \n * @extends OrionError\n */\nexport default class UserError extends OrionError {\n /**\n * Creates a new UserError instance.\n * \n * @param code - Error code identifier. If only one parameter is provided,\n * this will be used as the message and code will default to 'error'.\n * @param message - Human-readable error message. Optional if code is provided.\n * @param extra - Additional error context or metadata.\n * \n * @example\n * // Basic usage\n * throw new UserError('invalid_input', 'The provided email is invalid')\n * \n * @example\n * // Using only a message (code will be 'error')\n * throw new UserError('Input validation failed')\n * \n * @example\n * // With extra metadata\n * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })\n */\n constructor(code: string, message?: string, extra?: any) {\n if (!message && code) {\n message = code\n code = 'error'\n }\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isUserError = true\n this.code = code\n this.extra = extra\n\n this.getInfo = () => {\n return {\n error: code,\n message,\n extra\n }\n }\n }\n}\n","/**\n * @file Exports all error classes used in the Orion framework\n */\n\nimport {OrionError} from './OrionError'\nimport type {OrionErrorInformation} from './OrionError'\nimport PermissionsError from './PermissionsError'\nimport UserError from './UserError'\n\n/**\n * Re-export all error types for convenient importing\n */\nexport {OrionError, PermissionsError, UserError}\nexport type {OrionErrorInformation}\n\n/**\n * Type guard to check if an error is an OrionError\n *\n * @param error - Any error object to test\n * @returns True if the error is an OrionError instance\n *\n * @example\n * try {\n * // some code that might throw\n * } catch (error) {\n * if (isOrionError(error)) {\n * // Handle Orion-specific error\n * console.log(error.code, error.getInfo())\n * } else {\n * // Handle general error\n * }\n * }\n */\nexport function isOrionError(error: any): error is OrionError {\n return Boolean(error && typeof error === 'object' && error.isOrionError === true)\n}\n\n/**\n * Type guard to check if an error is a UserError\n *\n * @param error - Any error object to test\n * @returns True if the error is a UserError instance\n */\nexport function isUserError(error: any): error is UserError {\n return Boolean(\n error && typeof error === 'object' && error.isOrionError === true && error.isUserError === true,\n )\n}\n\n/**\n * Type guard to check if an error is a PermissionsError\n *\n * @param error - Any error object to test\n * @returns True if the error is a PermissionsError instance\n */\nexport function isPermissionsError(error: any): error is PermissionsError {\n return Boolean(\n error &&\n typeof error === 'object' &&\n error.isOrionError === true &&\n error.isPermissionsError === true,\n )\n}\n","// from https://github.com/koajs/compose/blob/master/index.js\n\n/**\n * Compose `middleware` returning\n * a fully valid middleware comprised\n * of all those which are passed.\n */\nexport function composeMiddlewares(middleware) {\n if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n for (const fn of middleware) {\n if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n }\n\n /**\n * @param {Object} context\n * @return {Promise}\n * @api public\n */\n\n return function (context, next?) {\n // last called middleware #\n let index = -1\n return dispatch(0)\n function dispatch(i) {\n if (i <= index) return Promise.reject(new Error('next() called multiple times'))\n index = i\n let fn = middleware[i]\n if (i === middleware.length) fn = next\n if (!fn) return Promise.resolve()\n try {\n return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n } catch (err) {\n return Promise.reject(err)\n }\n }\n }\n}\n","/**\n * Executes an asynchronous function with automatic retries on failure.\n * \n * This utility attempts to execute the provided function and automatically\n * retries if it fails, with a specified delay between attempts. It will\n * continue retrying until either the function succeeds or the maximum\n * number of retries is reached.\n * \n * @template TFunc Type of the function to execute (must return a Promise)\n * @param fn - The asynchronous function to execute\n * @param retries - The maximum number of retry attempts after the initial attempt\n * @param timeout - The delay in milliseconds between retry attempts\n * @returns A promise that resolves with the result of the function or rejects with the last error\n * \n * @example\n * // Retry an API call up to 3 times with 1 second between attempts\n * const result = await executeWithRetries(\n * () => fetchDataFromApi(),\n * 3,\n * 1000\n * );\n */\nexport function executeWithRetries<TFunc extends () => Promise<any>>(\n fn: TFunc,\n retries: number,\n timeout: number\n): Promise<ReturnType<TFunc>> {\n return new Promise((resolve, reject) => {\n const retry = async (retries: number) => {\n try {\n const result = await fn()\n resolve(result)\n } catch (error) {\n if (retries > 0) {\n setTimeout(() => retry(retries - 1), timeout)\n } else {\n reject(error)\n }\n }\n }\n retry(retries)\n })\n}\n","import crypto from 'crypto';\nconst rnds8Pool = new Uint8Array(256); // # of random values to pre-allocate\n\nlet poolPtr = rnds8Pool.length;\nexport default function rng() {\n if (poolPtr > rnds8Pool.length - 16) {\n crypto.randomFillSync(rnds8Pool);\n poolPtr = 0;\n }\n\n return rnds8Pool.slice(poolPtr, poolPtr += 16);\n}","export default /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;","import REGEX from './regex.js';\n\nfunction validate(uuid) {\n return typeof uuid === 'string' && REGEX.test(uuid);\n}\n\nexport default validate;","import validate from './validate.js';\n/**\n * Convert array of 16 byte values to UUID string format of the form:\n * XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX\n */\n\nconst byteToHex = [];\n\nfor (let i = 0; i < 256; ++i) {\n byteToHex.push((i + 0x100).toString(16).substr(1));\n}\n\nfunction stringify(arr, offset = 0) {\n // Note: Be careful editing this code! It's been tuned for performance\n // and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434\n const uuid = (byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + '-' + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + '-' + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + '-' + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + '-' + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]]).toLowerCase(); // Consistency check for valid UUID. If this throws, it's likely due to one\n // of the following:\n // - One or more input array values don't map to a hex octet (leading to\n // \"undefined\" in the uuid)\n // - Invalid input values for the RFC `version` or `variant` fields\n\n if (!validate(uuid)) {\n throw TypeError('Stringified UUID is invalid');\n }\n\n return uuid;\n}\n\nexport default stringify;","import rng from './rng.js';\nimport stringify from './stringify.js';\n\nfunction v4(options, buf, offset) {\n options = options || {};\n const rnds = options.random || (options.rng || rng)(); // Per 4.4, set bits for version and `clock_seq_hi_and_reserved`\n\n rnds[6] = rnds[6] & 0x0f | 0x40;\n rnds[8] = rnds[8] & 0x3f | 0x80; // Copy bytes to buffer, if provided\n\n if (buf) {\n offset = offset || 0;\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = rnds[i];\n }\n\n return buf;\n }\n\n return stringify(rnds);\n}\n\nexport default v4;","import { v4 as uuidv4 } from 'uuid'\n\nexport function generateUUID() {\n return uuidv4()\n}\n\nexport function generateUUIDWithPrefix(prefix: string) {\n return `${prefix}-${generateUUID()}`\n}\n","/**\n * Removes diacritical marks (accents) from text without any other modifications.\n * This is the most basic normalization function that others build upon.\n * \n * @param text - The input string to process\n * @returns String with accents removed but otherwise unchanged\n */\nexport function removeAccentsOnly(text: string) {\n if (!text) return ''\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: Removes diacritical marks (accents)\n return text.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '')\n}\n\n/**\n * Normalizes text by removing diacritical marks (accents) and trimming whitespace.\n * Builds on removeAccentsOnly and adds whitespace trimming.\n * \n * @param text - The input string to normalize\n * @returns Normalized string with accents removed and whitespace trimmed\n */\nexport function removeAccentsAndTrim(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text).trim()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * \n * Builds on removeAccentsAndTrim and adds lowercase conversion.\n * Useful for case-insensitive and accent-insensitive text searching.\n * \n * @param text - The input string to normalize for search\n * @returns Search-optimized string in lowercase with accents removed\n */\nexport function normalizeForSearch(text: string) {\n if (!text) return ''\n return removeAccentsAndTrim(text).toLowerCase()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Removing all spaces\n * \n * Builds on normalizeForSearch and removes all whitespace.\n * Useful for compact search indexes or when spaces should be ignored in searches.\n * \n * @param text - The input string to normalize for compact search\n * @returns Compact search-optimized string with no spaces\n */\nexport function normalizeForCompactSearch(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/\\s/g, '')\n}\n\n/**\n * Normalizes text for search token processing by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Replacing all non-alphanumeric characters with spaces\n * \n * Builds on normalizeForSearch and replaces non-alphanumeric characters with spaces.\n * Useful for tokenizing search terms where special characters should be treated as word separators.\n * \n * @param text - The input string to normalize for tokenized search\n * @returns Search token string with only alphanumeric characters and spaces\n */\nexport function normalizeForSearchToken(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/[^0-9a-z]/gi, ' ')\n}\n\n/**\n * Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).\n * Performs the following transformations:\n * - Removes accents/diacritical marks\n * - Replaces special characters with hyphens\n * - Ensures only alphanumeric characters, hyphens, periods, and underscores remain\n * - Replaces multiple consecutive hyphens with a single hyphen\n * - Removes leading/trailing hyphens\n * \n * @param text - The input string to normalize for file key usage\n * @returns A storage-safe string suitable for use as a file key\n */\nexport function normalizeForFileKey(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text)\n // Replace spaces and unwanted characters with hyphens\n .replace(/[^a-zA-Z0-9-._]/g, '-')\n // Replace multiple consecutive hyphens with single hyphen\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .trim()\n .replace(/^-+|-+$/g, '')\n}\n","import { normalizeForSearchToken } from './normalize'\n\n/**\n * Generates an array of search tokens from input text and optional metadata.\n * \n * This function processes text by:\n * 1. Converting it to an array of strings (if not already)\n * 2. Filtering out falsy values\n * 3. Normalizing each string (removing accents, special characters)\n * 4. Splitting by spaces to create individual tokens\n * 5. Optionally adding metadata tokens in the format \"_key:value\"\n * \n * @param text - String or array of strings to tokenize\n * @param meta - Optional metadata object where each key-value pair becomes a token\n * @returns Array of normalized search tokens\n * \n * @example\n * // Returns ['hello', 'world']\n * getSearchTokens('Hello, World!') \n * \n * @example\n * // Returns ['hello', 'world', '_id:123']\n * getSearchTokens('Hello, World!', { id: '123' })\n */\nexport function getSearchTokens(text: string[] | string, meta?: Record<string, string>) {\n const stringArray = Array.isArray(text) ? text : [text]\n const tokens = stringArray\n .filter(Boolean)\n .map(text => String(text))\n .flatMap(word => {\n return normalizeForSearchToken(word).split(' ').filter(Boolean)\n })\n\n if (meta) {\n for (const key in meta) {\n tokens.push(`_${key}:${meta[key]}`)\n }\n }\n\n return tokens\n}\n\n/**\n * Interface for parameters used in generating search queries from tokens.\n * \n * @property filter - Optional string to filter search results\n * @property [key: string] - Additional key-value pairs for metadata filtering\n */\nexport interface SearchQueryForTokensParams {\n filter?: string\n [key: string]: string\n}\n\n/**\n * Options for customizing the search query generation behavior.\n * Currently empty but provided for future extensibility.\n */\nexport type SearchQueryForTokensOptions = {}\n\n/**\n * Generates a MongoDB-compatible query object based on the provided parameters.\n * \n * This function:\n * 1. Processes any filter text into RegExp tokens for prefix matching\n * 2. Adds metadata filters based on additional properties in the params object\n * 3. Returns a query object with the $all operator for MongoDB queries\n * \n * @param params - Parameters for generating the search query\n * @param _options - Options for customizing search behavior (reserved for future use)\n * @returns A MongoDB-compatible query object with format { $all: [...tokens] }\n * \n * @example\n * // Returns { $all: [/^hello/, /^world/] }\n * getSearchQueryForTokens({ filter: 'Hello World' })\n * \n * @example\n * // Returns { $all: [/^search/, '_category:books'] }\n * getSearchQueryForTokens({ filter: 'search', category: 'books' })\n */\nexport function getSearchQueryForTokens(\n params: SearchQueryForTokensParams = {},\n _options: SearchQueryForTokensOptions = {},\n) {\n const searchTokens: (string | RegExp)[] = []\n\n if (params.filter) {\n const filterTokens = getSearchTokens(params.filter).map(token => new RegExp(`^${token}`))\n searchTokens.push(...filterTokens)\n }\n\n for (const key in params) {\n if (key === 'filter') continue\n if (!params[key]) continue\n searchTokens.push(`_${key}:${params[key]}`)\n }\n\n return { $all: searchTokens }\n}\n","function lastOfString(string: string, last: number) {\n return string.substring(string.length - last, string.length)\n}\n\nexport function shortenMongoId(string: string) {\n return lastOfString(string, 5).toUpperCase()\n}\n"],"mappings":";AAGA,IAAO,gBAAQ,CAAC,SAAgC;AAC9C,SAAO,IAAI,QAAQ,aAAW,WAAW,SAAS,IAAI,CAAC;AACzD;;;ACLA,OAAO,UAAU;AAEF,SAAR,mBAAkB,QAAqB;AAC5C,SAAO,KAAK,MAAM;AACpB;;;ACJA,OAAO,YAAY;AAEnB,IAAM,qBAAqB;AAE3B,IAAM,YAAY,SAAU,QAAQ;AAClC,MAAI,WAAW,KAAK,KAAK,SAAS,CAAC;AACnC,MAAI;AAGJ,MAAI;AACF,YAAQ,OAAO,YAAY,QAAQ;AAAA,EACrC,SAAS,GAAG;AAEV,YAAQ,OAAO,kBAAkB,QAAQ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1B,QAAQ,oBAAoB,GAAG,EAE/B,QAAQ,OAAO,GAAG,EAElB,KAAK,EACL,QAAQ,YAAY,EAAE;AAC3B;;;AC5EO,SAAS,gBAAgB,MAAyB,MAA+B;AACtF,QAAM,cAAc,MAAM,QAAQ,IAAI,IAAI,OAAO,CAAC,IAAI;AACtD,QAAM,SAAS,YACZ,OAAO,OAAO,EACd,IAAI,CAAAC,UAAQ,OAAOA,KAAI,CAAC,EACxB,QAAQ,UAAQ;AACf,WAAO,wBAAwB,IAAI,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAChE,CAAC;AAEH,MAAI,MAAM;AACR,eAAW,OAAO,MAAM;AACtB,aAAO,KAAK,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC,EAAE;AAAA,IACpC;AAAA,EACF;AAEA,SAAO;AACT;AAuCO,SAAS,wBACd,SAAqC,CAAC,GACtC,WAAwC,CAAC,GACzC;AACA,QAAM,eAAoC,CAAC;AAE3C,MAAI,OAAO,QAAQ;AACjB,UAAM,eAAe,gBAAgB,OAAO,MAAM,EAAE,IAAI,WAAS,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;AACxF,iBAAa,KAAK,GAAG,YAAY;AAAA,EACnC;AAEA,aAAW,OAAO,QAAQ;AACxB,QAAI,QAAQ,SAAU;AACtB,QAAI,CAAC,OAAO,GAAG,EAAG;AAClB,iBAAa,KAAK,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,EAAE;AAAA,EAC5C;AAEA,SAAO,EAAE,MAAM,aAAa;AAC9B;;;ACjGA,SAAS,aAAa,QAAgB,MAAc;AAClD,SAAO,OAAO,UAAU,OAAO,SAAS,MAAM,OAAO,MAAM;AAC7D;AAEO,SAAS,eAAe,QAAgB;AAC7C,SAAO,aAAa,QAAQ,CAAC,EAAE,YAAY;AAC7C;","names":["retries","crypto","text"]}
1
+ {"version":3,"sources":["../src/sleep.ts","../src/hashObject.ts","../src/generateId.ts","../src/createMap.ts","../src/createMapArray.ts","../src/Errors/OrionError.ts","../src/Errors/PermissionsError.ts","../src/Errors/UserError.ts","../src/Errors/index.ts","../src/composeMiddlewares.ts","../src/retries.ts","../src/generateUUID.ts","../src/normalize.ts","../src/searchTokens.ts","../src/shortenMongoId.ts"],"sourcesContent":["/**\n * Creates a timeout with a promise\n */\nexport default (time: number): Promise<void> => {\n return new Promise(resolve => setTimeout(resolve, time))\n}\n","import hash from 'object-hash'\n\nexport default function (object: any): string {\n return hash(object)\n}\n","import crypto from 'crypto'\n\nconst UNMISTAKABLE_CHARS = '23456789ABCDEFGHJKLMNPQRSTWXYZabcdefghjkmnopqrstuvwxyz'\n\nconst hexString = function (digits) {\n var numBytes = Math.ceil(digits / 2)\n var bytes\n // Try to get cryptographically strong randomness. Fall back to\n // non-cryptographically strong if not available.\n try {\n bytes = crypto.randomBytes(numBytes)\n } catch (e) {\n // XXX should re-throw any error except insufficient entropy\n bytes = crypto.pseudoRandomBytes(numBytes)\n }\n var result = bytes.toString('hex')\n // If the number of digits is odd, we'll have generated an extra 4 bits\n // of randomness, so we need to trim the last digit.\n return result.substring(0, digits)\n}\n\nconst fraction = function () {\n var numerator = parseInt(hexString(8), 16)\n return numerator * 2.3283064365386963e-10 // 2^-32\n}\n\nconst choice = function (arrayOrString) {\n var index = Math.floor(fraction() * arrayOrString.length)\n if (typeof arrayOrString === 'string') return arrayOrString.substr(index, 1)\n else return arrayOrString[index]\n}\n\nconst randomString = function (charsCount, alphabet) {\n var digits = []\n for (var i = 0; i < charsCount; i++) {\n digits[i] = choice(alphabet)\n }\n return digits.join('')\n}\n\n/**\n * Returns a random ID\n * @param charsCount length of the ID\n * @param chars characters used to generate the ID\n */\nexport default function generateId(\n charsCount?: number,\n chars: string = UNMISTAKABLE_CHARS,\n): string {\n if (!charsCount) {\n charsCount = 17\n }\n\n return randomString(charsCount, chars)\n}\n","/**\n * Creates a map (object) from an array of items, using a specified property as the key.\n *\n * This utility transforms an array of objects into a lookup object/dictionary where\n * each item in the array becomes a value in the map, indexed by the specified property.\n * If multiple items have the same key value, only the last one will be preserved.\n *\n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are the original items\n *\n * @example\n * // Returns { '1': { id: 1, name: 'Item 1' }, '2': { id: 2, name: 'Item 2' } }\n * createMap([{ id: 1, name: 'Item 1' }, { id: 2, name: 'Item 2' }], 'id')\n */\nexport default function createMap<T>(array: Array<T>, key: string = '_id'): Record<string, T> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = item\n }\n\n return map\n}\n","/**\n * Creates a grouped map from an array of items, using a specified property as the key.\n *\n * This utility transforms an array of objects into a lookup object/dictionary where\n * each value is an array of items sharing the same key value. Unlike createMap,\n * this function preserves all items with the same key by grouping them in arrays.\n *\n * @template T The type of items in the input array\n * @param array - The input array of items to transform into a grouped map\n * @param key - The property name to use as keys in the resulting map (defaults to '_id')\n * @returns A record object where keys are values of the specified property and values are arrays of items\n *\n * @example\n * // Returns { 'category1': [{ id: 1, category: 'category1' }, { id: 3, category: 'category1' }],\n * // 'category2': [{ id: 2, category: 'category2' }] }\n * createMapArray([\n * { id: 1, category: 'category1' },\n * { id: 2, category: 'category2' },\n * { id: 3, category: 'category1' }\n * ], 'category')\n */\nexport default function createMapArray<T>(\n array: Array<T>,\n key: string = '_id',\n): Record<string, Array<T>> {\n const map = {}\n\n for (const item of array) {\n map[item[key]] = map[item[key]] || []\n map[item[key]].push(item)\n }\n\n return map\n}\n","/**\n * Interface representing the standardized error information structure for Orion errors.\n * This is used by the getInfo method to provide consistent error reporting.\n */\nexport interface OrionErrorInformation {\n /** The error code or identifier */\n error: string\n /** Human-readable error message */\n message: string\n /** Additional error metadata or context */\n extra: any\n /** The sub-type of error. For example for permissions errors it could be 'read', 'write', 'admin' */\n type?: string\n}\n\n/**\n * Base error class for all Orion-specific errors.\n *\n * This abstract class provides common properties and methods for all error types\n * used in the Orion framework. It's extended by more specific error classes\n * like UserError and PermissionsError.\n *\n * @property isOrionError - Flag indicating this is an Orion error (always true)\n * @property isUserError - Flag indicating if this is a user-facing error\n * @property isPermissionsError - Flag indicating if this is a permissions-related error\n * @property code - Error code for identifying the error type\n * @property extra - Additional error context or metadata\n */\nexport class OrionError extends Error {\n isOrionError = true\n\n isUserError: boolean\n isPermissionsError: boolean\n code: string\n extra: any\n\n /**\n * Returns a standardized representation of the error information.\n * @returns An object containing error details in a consistent format\n */\n getInfo: () => OrionErrorInformation\n}\n","import {OrionError} from './OrionError'\n\n/**\n * Error class for permission-related errors in the Orion framework.\n *\n * PermissionsError represents authorization failures where a user or client\n * attempts to perform an action they don't have permission to execute.\n * This is used to distinguish security/permissions errors from other types\n * of errors for proper error handling and user feedback.\n *\n * @extends OrionError\n */\nexport default class PermissionsError extends OrionError {\n /**\n * Creates a new PermissionsError instance.\n *\n * @param permissionErrorType - Identifies the specific permission that was violated\n * (e.g., 'read', 'write', 'admin')\n * @param extra - Additional error context or metadata. Can include a custom message\n * via the message property.\n *\n * @example\n * // Basic usage\n * throw new PermissionsError('delete_document')\n *\n * @example\n * // With custom message\n * throw new PermissionsError('access_admin', { message: 'Admin access required' })\n *\n * @example\n * // With additional context\n * throw new PermissionsError('edit_user', {\n * userId: 'user123',\n * requiredRole: 'admin'\n * })\n */\n constructor(permissionErrorType, extra: any = {}) {\n // Calling parent constructor of base Error class.\n const message =\n extra.message || `Client is not allowed to perform this action [${permissionErrorType}]`\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isPermissionsError = true\n this.code = 'PermissionsError'\n this.extra = extra\n\n this.getInfo = () => {\n return {\n ...extra,\n error: 'PermissionsError',\n message,\n type: permissionErrorType,\n }\n }\n }\n}\n","import {OrionError} from './OrionError'\n\n/**\n * Error class for user-facing errors in the Orion framework.\n *\n * UserError is designed to represent errors that should be displayed to end users,\n * as opposed to system errors or unexpected failures. These errors typically represent\n * validation issues, business rule violations, or other expected error conditions.\n *\n * @extends OrionError\n */\nexport default class UserError extends OrionError {\n /**\n * Creates a new UserError instance.\n *\n * @param code - Error code identifier. If only one parameter is provided,\n * this will be used as the message and code will default to 'error'.\n * @param message - Human-readable error message. Optional if code is provided.\n * @param extra - Additional error context or metadata.\n *\n * @example\n * // Basic usage\n * throw new UserError('invalid_input', 'The provided email is invalid')\n *\n * @example\n * // Using only a message (code will be 'error')\n * throw new UserError('Input validation failed')\n *\n * @example\n * // With extra metadata\n * throw new UserError('rate_limit', 'Too many requests', { maxRequests: 100 })\n */\n constructor(code: string, message?: string, extra?: any) {\n if (!message && code) {\n message = code\n code = 'error'\n }\n\n super(message)\n Error.captureStackTrace(this, this.constructor)\n\n this.isOrionError = true\n this.isUserError = true\n this.code = code\n this.extra = extra\n\n this.getInfo = () => {\n return {\n error: code,\n message,\n extra,\n }\n }\n }\n}\n","/**\n * @file Exports all error classes used in the Orion framework\n */\n\nimport {OrionError} from './OrionError'\nimport type {OrionErrorInformation} from './OrionError'\nimport PermissionsError from './PermissionsError'\nimport UserError from './UserError'\n\n/**\n * Re-export all error types for convenient importing\n */\nexport {OrionError, PermissionsError, UserError}\nexport type {OrionErrorInformation}\n\n/**\n * Type guard to check if an error is an OrionError\n *\n * @param error - Any error object to test\n * @returns True if the error is an OrionError instance\n *\n * @example\n * try {\n * // some code that might throw\n * } catch (error) {\n * if (isOrionError(error)) {\n * // Handle Orion-specific error\n * console.log(error.code, error.getInfo())\n * } else {\n * // Handle general error\n * }\n * }\n */\nexport function isOrionError(error: any): error is OrionError {\n return Boolean(error && typeof error === 'object' && error.isOrionError === true)\n}\n\n/**\n * Type guard to check if an error is a UserError\n *\n * @param error - Any error object to test\n * @returns True if the error is a UserError instance\n */\nexport function isUserError(error: any): error is UserError {\n return Boolean(\n error && typeof error === 'object' && error.isOrionError === true && error.isUserError === true,\n )\n}\n\n/**\n * Type guard to check if an error is a PermissionsError\n *\n * @param error - Any error object to test\n * @returns True if the error is a PermissionsError instance\n */\nexport function isPermissionsError(error: any): error is PermissionsError {\n return Boolean(\n error &&\n typeof error === 'object' &&\n error.isOrionError === true &&\n error.isPermissionsError === true,\n )\n}\n","// from https://github.com/koajs/compose/blob/master/index.js\n\n/**\n * Compose `middleware` returning\n * a fully valid middleware comprised\n * of all those which are passed.\n */\nexport function composeMiddlewares(middleware) {\n if (!Array.isArray(middleware)) throw new TypeError('Middleware stack must be an array!')\n for (const fn of middleware) {\n if (typeof fn !== 'function') throw new TypeError('Middleware must be composed of functions!')\n }\n\n /**\n * @param {Object} context\n * @return {Promise}\n * @api public\n */\n\n return function (context, next?) {\n // last called middleware #\n let index = -1\n return dispatch(0)\n function dispatch(i) {\n if (i <= index) return Promise.reject(new Error('next() called multiple times'))\n index = i\n let fn = middleware[i]\n if (i === middleware.length) fn = next\n if (!fn) return Promise.resolve()\n try {\n return Promise.resolve(fn(context, dispatch.bind(null, i + 1)))\n } catch (err) {\n return Promise.reject(err)\n }\n }\n }\n}\n","/**\n * Executes an asynchronous function with automatic retries on failure.\n *\n * This utility attempts to execute the provided function and automatically\n * retries if it fails, with a specified delay between attempts. It will\n * continue retrying until either the function succeeds or the maximum\n * number of retries is reached.\n *\n * @template TFunc Type of the function to execute (must return a Promise)\n * @param fn - The asynchronous function to execute\n * @param retries - The maximum number of retry attempts after the initial attempt\n * @param timeout - The delay in milliseconds between retry attempts\n * @returns A promise that resolves with the result of the function or rejects with the last error\n *\n * @example\n * // Retry an API call up to 3 times with 1 second between attempts\n * const result = await executeWithRetries(\n * () => fetchDataFromApi(),\n * 3,\n * 1000\n * );\n */\nexport function executeWithRetries<TFunc extends () => Promise<any>>(\n fn: TFunc,\n retries: number,\n timeout: number,\n): Promise<ReturnType<TFunc>> {\n return new Promise((resolve, reject) => {\n const retry = async (retries: number) => {\n try {\n const result = await fn()\n resolve(result)\n } catch (error) {\n if (retries > 0) {\n setTimeout(() => retry(retries - 1), timeout)\n } else {\n reject(error)\n }\n }\n }\n retry(retries)\n })\n}\n","import {v4 as uuidv4} from 'uuid'\n\nexport function generateUUID() {\n return uuidv4()\n}\n\nexport function generateUUIDWithPrefix(prefix: string) {\n return `${prefix}-${generateUUID()}`\n}\n","/**\n * Removes diacritical marks (accents) from text without any other modifications.\n * This is the most basic normalization function that others build upon.\n *\n * @param text - The input string to process\n * @returns String with accents removed but otherwise unchanged\n */\nexport function removeAccentsOnly(text: string) {\n if (!text) return ''\n // biome-ignore lint/suspicious/noMisleadingCharacterClass: Removes diacritical marks (accents)\n return text.normalize('NFD').replace(/[\\u0300-\\u036f]/g, '')\n}\n\n/**\n * Normalizes text by removing diacritical marks (accents) and trimming whitespace.\n * Builds on removeAccentsOnly and adds whitespace trimming.\n *\n * @param text - The input string to normalize\n * @returns Normalized string with accents removed and whitespace trimmed\n */\nexport function removeAccentsAndTrim(text: string) {\n if (!text) return ''\n return removeAccentsOnly(text).trim()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n *\n * Builds on removeAccentsAndTrim and adds lowercase conversion.\n * Useful for case-insensitive and accent-insensitive text searching.\n *\n * @param text - The input string to normalize for search\n * @returns Search-optimized string in lowercase with accents removed\n */\nexport function normalizeForSearch(text: string) {\n if (!text) return ''\n return removeAccentsAndTrim(text).toLowerCase()\n}\n\n/**\n * Normalizes text for search purposes by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Removing all spaces\n *\n * Builds on normalizeForSearch and removes all whitespace.\n * Useful for compact search indexes or when spaces should be ignored in searches.\n *\n * @param text - The input string to normalize for compact search\n * @returns Compact search-optimized string with no spaces\n */\nexport function normalizeForCompactSearch(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/\\s/g, '')\n}\n\n/**\n * Normalizes text for search token processing by:\n * - Removing diacritical marks (accents)\n * - Converting to lowercase\n * - Trimming whitespace\n * - Replacing all non-alphanumeric characters with spaces\n *\n * Builds on normalizeForSearch and replaces non-alphanumeric characters with spaces.\n * Useful for tokenizing search terms where special characters should be treated as word separators.\n *\n * @param text - The input string to normalize for tokenized search\n * @returns Search token string with only alphanumeric characters and spaces\n */\nexport function normalizeForSearchToken(text: string) {\n if (!text) return ''\n return normalizeForSearch(text).replace(/[^0-9a-z]/gi, ' ')\n}\n\n/**\n * Normalizes a string specifically for use as a file key (e.g., in S3 or other storage systems).\n * Performs the following transformations:\n * - Removes accents/diacritical marks\n * - Replaces special characters with hyphens\n * - Ensures only alphanumeric characters, hyphens, periods, and underscores remain\n * - Replaces multiple consecutive hyphens with a single hyphen\n * - Removes leading/trailing hyphens\n *\n * @param text - The input string to normalize for file key usage\n * @returns A storage-safe string suitable for use as a file key\n */\nexport function normalizeForFileKey(text: string) {\n if (!text) return ''\n return (\n removeAccentsOnly(text)\n // Replace spaces and unwanted characters with hyphens\n .replace(/[^a-zA-Z0-9-._]/g, '-')\n // Replace multiple consecutive hyphens with single hyphen\n .replace(/-+/g, '-')\n // Remove leading/trailing hyphens\n .trim()\n .replace(/^-+|-+$/g, '')\n )\n}\n","import {normalizeForSearchToken} from './normalize'\n\n/**\n * Generates an array of search tokens from input text and optional metadata.\n *\n * This function processes text by:\n * 1. Converting it to an array of strings (if not already)\n * 2. Filtering out falsy values\n * 3. Normalizing each string (removing accents, special characters)\n * 4. Splitting by spaces to create individual tokens\n * 5. Optionally adding metadata tokens in the format \"_key:value\"\n *\n * @param text - String or array of strings to tokenize\n * @param meta - Optional metadata object where each key-value pair becomes a token\n * @returns Array of normalized search tokens\n *\n * @example\n * // Returns ['hello', 'world']\n * getSearchTokens('Hello, World!')\n *\n * @example\n * // Returns ['hello', 'world', '_id:123']\n * getSearchTokens('Hello, World!', { id: '123' })\n */\nexport function getSearchTokens(text: string[] | string, meta?: Record<string, string>) {\n const stringArray = Array.isArray(text) ? text : [text]\n const tokens = stringArray\n .filter(Boolean)\n .map(text => String(text))\n .flatMap(word => {\n return normalizeForSearchToken(word).split(' ').filter(Boolean)\n })\n\n if (meta) {\n for (const key in meta) {\n tokens.push(`_${key}:${meta[key]}`)\n }\n }\n\n return tokens\n}\n\n/**\n * Interface for parameters used in generating search queries from tokens.\n *\n * @property filter - Optional string to filter search results\n * @property [key: string] - Additional key-value pairs for metadata filtering\n */\nexport interface SearchQueryForTokensParams {\n filter?: string\n [key: string]: string\n}\n\n/**\n * Options for customizing the search query generation behavior.\n * Currently empty but provided for future extensibility.\n */\nexport type SearchQueryForTokensOptions = {}\n\n/**\n * Generates a MongoDB-compatible query object based on the provided parameters.\n *\n * This function:\n * 1. Processes any filter text into RegExp tokens for prefix matching\n * 2. Adds metadata filters based on additional properties in the params object\n * 3. Returns a query object with the $all operator for MongoDB queries\n *\n * @param params - Parameters for generating the search query\n * @param _options - Options for customizing search behavior (reserved for future use)\n * @returns A MongoDB-compatible query object with format { $all: [...tokens] }\n *\n * @example\n * // Returns { $all: [/^hello/, /^world/] }\n * getSearchQueryForTokens({ filter: 'Hello World' })\n *\n * @example\n * // Returns { $all: [/^search/, '_category:books'] }\n * getSearchQueryForTokens({ filter: 'search', category: 'books' })\n */\nexport function getSearchQueryForTokens(\n params: SearchQueryForTokensParams = {},\n _options: SearchQueryForTokensOptions = {},\n) {\n const searchTokens: (string | RegExp)[] = []\n\n if (params.filter) {\n const filterTokens = getSearchTokens(params.filter).map(token => new RegExp(`^${token}`))\n searchTokens.push(...filterTokens)\n }\n\n for (const key in params) {\n if (key === 'filter') continue\n if (!params[key]) continue\n searchTokens.push(`_${key}:${params[key]}`)\n }\n\n return {$all: searchTokens}\n}\n","function lastOfString(string: string, last: number) {\n return string.substring(string.length - last, string.length)\n}\n\nexport function shortenMongoId(string: string) {\n return lastOfString(string, 5).toUpperCase()\n}\n"],"mappings":";AAGA,IAAO,gBAAQ,CAAC,SAAgC;AAC9C,SAAO,IAAI,QAAQ,aAAW,WAAW,SAAS,IAAI,CAAC;AACzD;;;ACLA,OAAO,UAAU;AAEF,SAAR,mBAAkB,QAAqB;AAC5C,SAAO,KAAK,MAAM;AACpB;;;ACJA,OAAO,YAA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OA,KAAI,CAAC,EACxB,QAAQ,UAAQ;AACf,WAAO,wBAAwB,IAAI,EAAE,MAAM,GAAG,EAAE,OAAO,OAAO;AAAA,EAChE,CAAC;AAEH,MAAI,MAAM;AACR,eAAW,OAAO,MAAM;AACtB,aAAO,KAAK,IAAI,GAAG,IAAI,KAAK,GAAG,CAAC,EAAE;AAAA,IACpC;AAAA,EACF;AAEA,SAAO;AACT;AAuCO,SAAS,wBACd,SAAqC,CAAC,GACtC,WAAwC,CAAC,GACzC;AACA,QAAM,eAAoC,CAAC;AAE3C,MAAI,OAAO,QAAQ;AACjB,UAAM,eAAe,gBAAgB,OAAO,MAAM,EAAE,IAAI,WAAS,IAAI,OAAO,IAAI,KAAK,EAAE,CAAC;AACxF,iBAAa,KAAK,GAAG,YAAY;AAAA,EACnC;AAEA,aAAW,OAAO,QAAQ;AACxB,QAAI,QAAQ,SAAU;AACtB,QAAI,CAAC,OAAO,GAAG,EAAG;AAClB,iBAAa,KAAK,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,EAAE;AAAA,EAC5C;AAEA,SAAO,EAAC,MAAM,aAAY;AAC5B;;;ACjGA,SAAS,aAAa,QAAgB,MAAc;AAClD,SAAO,OAAO,UAAU,OAAO,SAAS,MAAM,OAAO,MAAM;AAC7D;AAEO,SAAS,eAAe,QAAgB;AAC7C,SAAO,aAAa,QAAQ,CAAC,EAAE,YAAY;AAC7C;","names":["retries","text"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@orion-js/helpers",
3
- "version": "4.0.0-next.3",
3
+ "version": "4.0.0-next.4",
4
4
  "main": "./dist/index.cjs",
5
5
  "module": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -15,12 +15,13 @@
15
15
  "author": "nicolaslopezj",
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
- "object-hash": "^2.2.0"
18
+ "object-hash": "^2.2.0",
19
+ "uuid": "^11.1.0"
19
20
  },
20
21
  "devDependencies": {
21
22
  "@types/node": "^18.0.0",
22
- "typescript": "^5.4.5",
23
23
  "tsup": "^8.0.1",
24
+ "typescript": "^5.4.5",
24
25
  "vitest": "^1.1.0"
25
26
  },
26
27
  "publishConfig": {