{"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';\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 (!Number.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","Number","isInteger","Error","hash","crypto","outputLength","Math","ceil","update","digest","substring"],"mappings":";;AAkBA;;;;;;;;;;;;;AAaC,IACM,SAASA,UAAAA,CAAWC,IAAY,EAAEC,GAAW,EAAA;AAClD,IAAA,IAAI,CAACC,MAAAA,CAAOC,SAAS,CAACF,GAAAA,CAAAA,IAAQA,OAAO,CAAA,EAAG;AACtC,QAAA,MAAM,IAAIG,KAAAA,CAAM,CAAC,uDAAuD,EAAEH,GAAAA,CAAAA,CAAK,CAAA;AACjF,IAAA;AAEA,IAAA,MAAMI,IAAAA,GAAOC,MAAAA,CAAOP,UAAU,CAAC,UAAA,EAAY;QAAEQ,YAAAA,EAAcC,IAAAA,CAAKC,IAAI,CAACR,GAAAA,GAAM,CAAA;AAAG,KAAA,CAAA,CAAGS,MAAM,CAACV,IAAAA,CAAAA;AACxF,IAAA,OAAOK,KAAKM,MAAM,CAAC,KAAA,CAAA,CAAOC,SAAS,CAAC,CAAA,EAAGX,GAAAA,CAAAA;AACzC;;;;"}