@langchain/core
Version:
Core LangChain.js abstractions and schemas
1 lines • 3.11 kB
Source Map (JSON)
{"version":3,"file":"v35.cjs","names":["parse","unsafeStringify"],"sources":["../../../src/utils/uuid/v35.ts"],"sourcesContent":["import parse from \"./parse.js\";\nimport { unsafeStringify } from \"./stringify.js\";\nimport type { UUIDTypes } from \"./types.js\";\n\nexport function stringToBytes(str: string) {\n // TODO: Use TextEncoder (see https://stackoverflow.com/a/48762658/109538)\n str = unescape(encodeURIComponent(str));\n\n const bytes = new Uint8Array(str.length);\n\n for (let i = 0; i < str.length; ++i) {\n bytes[i] = str.charCodeAt(i);\n }\n\n return bytes;\n}\n\nexport const DNS = \"6ba7b810-9dad-11d1-80b4-00c04fd430c8\";\nexport const URL = \"6ba7b811-9dad-11d1-80b4-00c04fd430c8\";\n\ntype HashFunction = (bytes: Uint8Array) => Uint8Array;\n\nexport default function v35<TBuf extends Uint8Array = Uint8Array>(\n version: 0x30 | 0x50,\n hash: HashFunction,\n value: string | Uint8Array,\n namespace: UUIDTypes,\n buf?: TBuf,\n offset?: number\n): UUIDTypes<TBuf> {\n const valueBytes: Uint8Array =\n typeof value === \"string\" ? stringToBytes(value) : value;\n const namespaceBytes: Uint8Array =\n typeof namespace === \"string\" ? parse(namespace) : namespace;\n\n if (typeof namespace === \"string\") {\n namespace = parse(namespace);\n }\n\n if (namespace?.length !== 16) {\n throw TypeError(\n \"Namespace must be array-like (16 iterable integer values, 0-255)\"\n );\n }\n\n // Compute hash of namespace and value, Per 4.3\n // Future: Use spread syntax when supported on all platforms, e.g. `bytes =\n // hashfunc([...namespace, ... value])`\n let bytes: Uint8Array = new Uint8Array(16 + valueBytes.length);\n bytes.set(namespaceBytes);\n bytes.set(valueBytes, namespaceBytes.length);\n bytes = hash(bytes);\n\n bytes[6] = (bytes[6] & 0x0f) | version;\n bytes[8] = (bytes[8] & 0x3f) | 0x80;\n\n if (buf) {\n offset ??= 0;\n if (offset < 0 || offset + 16 > buf.length) {\n throw new RangeError(\n `UUID byte range ${offset}:${offset + 15} is out of buffer bounds`\n );\n }\n\n for (let i = 0; i < 16; ++i) {\n buf[offset + i] = bytes[i];\n }\n\n return buf;\n }\n\n return unsafeStringify(bytes);\n}\n"],"mappings":";;;AAIA,SAAgB,cAAc,KAAa;CAEzC,MAAM,SAAS,mBAAmB,GAAG,CAAC;CAEtC,MAAM,QAAQ,IAAI,WAAW,IAAI,MAAM;CAEvC,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,QAAQ,EAAE,GAChC,MAAM,KAAK,IAAI,WAAW,CAAC;CAG7B,OAAO;AACT;AAEA,MAAa,MAAM;AACnB,MAAa,MAAM;AAInB,SAAwB,IACtB,SACA,MACA,OACA,WACA,KACA,QACiB;CACjB,MAAM,aACJ,OAAO,UAAU,WAAW,cAAc,KAAK,IAAI;CACrD,MAAM,iBACJ,OAAO,cAAc,WAAWA,cAAAA,QAAM,SAAS,IAAI;CAErD,IAAI,OAAO,cAAc,UACvB,YAAYA,cAAAA,QAAM,SAAS;CAG7B,IAAI,WAAW,WAAW,IACxB,MAAM,UACJ,kEACF;CAMF,IAAI,QAAoB,IAAI,WAAW,KAAK,WAAW,MAAM;CAC7D,MAAM,IAAI,cAAc;CACxB,MAAM,IAAI,YAAY,eAAe,MAAM;CAC3C,QAAQ,KAAK,KAAK;CAElB,MAAM,KAAM,MAAM,KAAK,KAAQ;CAC/B,MAAM,KAAM,MAAM,KAAK,KAAQ;CAE/B,IAAI,KAAK;EACP,WAAW;EACX,IAAI,SAAS,KAAK,SAAS,KAAK,IAAI,QAClC,MAAM,IAAI,WACR,mBAAmB,OAAO,GAAG,SAAS,GAAG,yBAC3C;EAGF,KAAK,IAAI,IAAI,GAAG,IAAI,IAAI,EAAE,GACxB,IAAI,SAAS,KAAK,MAAM;EAG1B,OAAO;CACT;CAEA,OAAOC,kBAAAA,gBAAgB,KAAK;AAC9B"}