{"version":3,"file":"hash.mjs","sources":["../../../src/utils/identifiers/hash.ts"],"sourcesContent":["/**\n * @fileoverview This file contains utility functions for shortening identifiers for use in a database schema.\n * The functions in this file are used to generate shorter names for database tables and columns\n * to avoid breaking the constraints of databases.\n *\n * IMPORTANT\n * Any changes here that result in a different output string from any of the naming methods will\n * cause the schema creation to delete data it doesn't recognize because the name\n * is different.\n *\n * If there are any test failures after updating this code, it means there is a breaking change that\n * will cause data loss, so beware; do not update the test to match your changes\n *\n * @internal\n */\n\nimport crypto from 'node:crypto';\nimport { isInteger } from 'lodash/fp';\n\n/**\n * Creates a hash of the given data with the specified string length as a string of hex characters\n *\n * @example\n * createHash(\"myData\", 5); // \"03f85\"\n * createHash(\"myData\", 2); // \"03\"\n * createHash(\"myData\", 1); // \"0\"\n *\n * @param data - The data to be hashed\n * @param len - The length of the hash\n * @returns The generated hash\n * @throws Error if the length is not a positive integer\n * @internal\n */\nexport function createHash(data: string, len: number): string {\n if (!isInteger(len) || len <= 0) {\n throw new Error(`createHash length must be a positive integer, received ${len}`);\n }\n\n const hash = crypto.createHash('shake256', { outputLength: Math.ceil(len / 2) }).update(data);\n return hash.digest('hex').substring(0, len);\n}\n"],"names":["createHash","data","len","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;;AAmBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAWC,CAAAA,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,SAAAA,CAAUD,GAAQA,CAAAA,IAAAA,GAAAA,IAAO,CAAG,EAAA;AAC/B,QAAA,MAAM,IAAIE,KAAM,CAAA,CAAC,uDAAuD,EAAEF,IAAI,CAAC,CAAA;AACjF;AAEA,IAAA,MAAMG,IAAOC,GAAAA,MAAAA,CAAON,UAAU,CAAC,UAAY,EAAA;QAAEO,YAAcC,EAAAA,IAAAA,CAAKC,IAAI,CAACP,GAAM,GAAA,CAAA;AAAG,KAAA,CAAA,CAAGQ,MAAM,CAACT,IAAAA,CAAAA;AACxF,IAAA,OAAOI,KAAKM,MAAM,CAAC,KAAOC,CAAAA,CAAAA,SAAS,CAAC,CAAGV,EAAAA,GAAAA,CAAAA;AACzC;;;;"}