UNPKG

@langchain/core

Version:
1 lines 2.21 kB
{"version":3,"file":"v1ToV6.cjs","names":["parse","unsafeStringify"],"sources":["../../../src/utils/uuid/v1ToV6.ts"],"sourcesContent":["import parse from \"./parse.js\";\nimport { unsafeStringify } from \"./stringify.js\";\nimport type { NonSharedArrayBuffer, UUIDTypes } from \"./types.js\";\n\n/**\n * Convert a v1 UUID to a v6 UUID\n *\n * @param {string|Uint8Array} uuid - The v1 UUID to convert to v6\n * @returns {string|Uint8Array} The v6 UUID as the same type as the `uuid` arg\n * (string or Uint8Array)\n */\nexport default function v1ToV6(uuid: string): string;\nexport default function v1ToV6(uuid: Uint8Array): NonSharedArrayBuffer;\nexport default function v1ToV6(\n uuid: string | Uint8Array\n): UUIDTypes<NonSharedArrayBuffer> {\n const v1Bytes = typeof uuid === \"string\" ? parse(uuid) : uuid;\n\n const v6Bytes = _v1ToV6(v1Bytes);\n\n return typeof uuid === \"string\" ? unsafeStringify(v6Bytes) : v6Bytes;\n}\n\n// Do the field transformation needed for v1 -> v6\nfunction _v1ToV6(v1Bytes: Uint8Array): NonSharedArrayBuffer {\n return Uint8Array.of(\n ((v1Bytes[6] & 0x0f) << 4) | ((v1Bytes[7] >> 4) & 0x0f),\n ((v1Bytes[7] & 0x0f) << 4) | ((v1Bytes[4] & 0xf0) >> 4),\n ((v1Bytes[4] & 0x0f) << 4) | ((v1Bytes[5] & 0xf0) >> 4),\n ((v1Bytes[5] & 0x0f) << 4) | ((v1Bytes[0] & 0xf0) >> 4),\n\n ((v1Bytes[0] & 0x0f) << 4) | ((v1Bytes[1] & 0xf0) >> 4),\n ((v1Bytes[1] & 0x0f) << 4) | ((v1Bytes[2] & 0xf0) >> 4),\n\n 0x60 | (v1Bytes[2] & 0x0f),\n v1Bytes[3],\n\n v1Bytes[8],\n v1Bytes[9],\n v1Bytes[10],\n v1Bytes[11],\n v1Bytes[12],\n v1Bytes[13],\n v1Bytes[14],\n v1Bytes[15]\n );\n}\n"],"mappings":";;;AAaA,SAAwB,OACtB,MACiC;CAGjC,MAAM,UAAU,QAFA,OAAO,SAAS,WAAWA,cAAAA,QAAM,KAAK,GAAG,KAEzB;AAEhC,QAAO,OAAO,SAAS,WAAWC,kBAAAA,gBAAgB,QAAQ,GAAG;;AAI/D,SAAS,QAAQ,SAA2C;AAC1D,QAAO,WAAW,IACd,QAAQ,KAAK,OAAS,IAAO,QAAQ,MAAM,IAAK,KAChD,QAAQ,KAAK,OAAS,KAAO,QAAQ,KAAK,QAAS,IACnD,QAAQ,KAAK,OAAS,KAAO,QAAQ,KAAK,QAAS,IACnD,QAAQ,KAAK,OAAS,KAAO,QAAQ,KAAK,QAAS,IAEnD,QAAQ,KAAK,OAAS,KAAO,QAAQ,KAAK,QAAS,IACnD,QAAQ,KAAK,OAAS,KAAO,QAAQ,KAAK,QAAS,GAErD,KAAQ,QAAQ,KAAK,IACrB,QAAQ,IAER,QAAQ,IACR,QAAQ,IACR,QAAQ,KACR,QAAQ,KACR,QAAQ,KACR,QAAQ,KACR,QAAQ,KACR,QAAQ,IACT"}