langsmith 0.5.22 → 0.5.24
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/client.cjs +365 -19
- package/dist/client.d.ts +116 -1
- package/dist/client.js +369 -23
- package/dist/evaluation/_runner.cjs +4 -7
- package/dist/evaluation/_runner.js +2 -5
- package/dist/evaluation/evaluate_comparative.cjs +10 -10
- package/dist/evaluation/evaluate_comparative.js +1 -1
- package/dist/evaluation/evaluator.cjs +2 -2
- package/dist/evaluation/evaluator.js +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +8 -7
- package/dist/run_trees.d.ts +7 -0
- package/dist/run_trees.js +7 -6
- package/dist/schemas.d.ts +54 -0
- package/dist/singletons/otel.cjs +3 -2
- package/dist/singletons/otel.js +4 -3
- package/dist/traceable.cjs +1 -2
- package/dist/traceable.js +1 -2
- package/dist/utils/_uuid.cjs +2 -2
- package/dist/utils/_uuid.js +1 -1
- package/dist/utils/env.cjs +33 -0
- package/dist/utils/env.d.ts +9 -0
- package/dist/utils/env.js +32 -0
- package/dist/utils/error.cjs +7 -0
- package/dist/utils/error.d.ts +1 -0
- package/dist/utils/error.js +6 -0
- package/dist/utils/fast-safe-stringify/index.cjs +203 -0
- package/dist/utils/fast-safe-stringify/index.d.ts +46 -0
- package/dist/utils/fast-safe-stringify/index.js +202 -0
- package/dist/utils/jestlike/index.cjs +5 -5
- package/dist/utils/jestlike/index.js +1 -1
- package/dist/utils/jestlike/vendor/evaluatedBy.cjs +3 -3
- package/dist/utils/jestlike/vendor/evaluatedBy.js +1 -1
- package/dist/utils/prompts.cjs +7 -2
- package/dist/utils/prompts.d.ts +6 -1
- package/dist/utils/prompts.js +6 -1
- package/dist/utils/serialize_worker.cjs +389 -0
- package/dist/utils/serialize_worker.d.ts +67 -0
- package/dist/utils/serialize_worker.js +383 -0
- package/dist/utils/uuid/src/index.cjs +24 -0
- package/dist/utils/uuid/src/index.d.ts +10 -0
- package/dist/utils/uuid/src/index.js +9 -0
- package/dist/utils/uuid/src/max.cjs +3 -0
- package/dist/utils/uuid/src/max.d.ts +2 -0
- package/dist/utils/uuid/src/max.js +1 -0
- package/dist/utils/uuid/src/nil.cjs +3 -0
- package/dist/utils/uuid/src/nil.d.ts +2 -0
- package/dist/utils/uuid/src/nil.js +1 -0
- package/dist/utils/uuid/src/parse.cjs +23 -0
- package/dist/utils/uuid/src/parse.d.ts +3 -0
- package/dist/utils/uuid/src/parse.js +18 -0
- package/dist/utils/uuid/src/regex.cjs +3 -0
- package/dist/utils/uuid/src/regex.d.ts +2 -0
- package/dist/utils/uuid/src/regex.js +1 -0
- package/dist/utils/uuid/src/rng.cjs +10 -0
- package/dist/utils/uuid/src/rng.d.ts +1 -0
- package/dist/utils/uuid/src/rng.js +7 -0
- package/dist/utils/uuid/src/sha1.cjs +75 -0
- package/dist/utils/uuid/src/sha1.d.ts +2 -0
- package/dist/utils/uuid/src/sha1.js +73 -0
- package/dist/utils/uuid/src/stringify.cjs +55 -0
- package/dist/utils/uuid/src/stringify.d.ts +3 -0
- package/dist/utils/uuid/src/stringify.js +49 -0
- package/dist/utils/uuid/src/types.cjs +2 -0
- package/dist/utils/uuid/src/types.d.ts +22 -0
- package/dist/utils/uuid/src/types.js +1 -0
- package/dist/utils/uuid/src/v35.cjs +52 -0
- package/dist/utils/uuid/src/v35.d.ts +7 -0
- package/dist/utils/uuid/src/v35.js +44 -0
- package/dist/utils/uuid/src/v4.cjs +40 -0
- package/dist/utils/uuid/src/v4.d.ts +4 -0
- package/dist/utils/uuid/src/v4.js +35 -0
- package/dist/utils/uuid/src/v5.cjs +50 -0
- package/dist/utils/uuid/src/v5.d.ts +9 -0
- package/dist/utils/uuid/src/v5.js +9 -0
- package/dist/utils/uuid/src/v7.cjs +88 -0
- package/dist/utils/uuid/src/v7.d.ts +9 -0
- package/dist/utils/uuid/src/v7.js +82 -0
- package/dist/utils/uuid/src/validate.cjs +10 -0
- package/dist/utils/uuid/src/validate.d.ts +2 -0
- package/dist/utils/uuid/src/validate.js +5 -0
- package/dist/utils/uuid/src/version.cjs +13 -0
- package/dist/utils/uuid/src/version.d.ts +2 -0
- package/dist/utils/uuid/src/version.js +8 -0
- package/dist/utils/worker_threads.browser.cjs +16 -0
- package/dist/utils/worker_threads.browser.d.ts +14 -0
- package/dist/utils/worker_threads.browser.js +13 -0
- package/dist/utils/worker_threads.cjs +16 -0
- package/dist/utils/worker_threads.d.ts +13 -0
- package/dist/utils/worker_threads.js +13 -0
- package/dist/uuid.cjs +2 -2
- package/dist/uuid.js +1 -1
- package/package.json +7 -5
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// Adapted from Chris Veness' SHA1 code at
|
|
2
|
+
// http://www.movable-type.co.uk/scripts/sha1.html
|
|
3
|
+
function f(s, x, y, z) {
|
|
4
|
+
switch (s) {
|
|
5
|
+
case 0:
|
|
6
|
+
return (x & y) ^ (~x & z);
|
|
7
|
+
case 1:
|
|
8
|
+
return x ^ y ^ z;
|
|
9
|
+
case 2:
|
|
10
|
+
return (x & y) ^ (x & z) ^ (y & z);
|
|
11
|
+
case 3:
|
|
12
|
+
return x ^ y ^ z;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
function ROTL(x, n) {
|
|
16
|
+
return (x << n) | (x >>> (32 - n));
|
|
17
|
+
}
|
|
18
|
+
function sha1(bytes) {
|
|
19
|
+
const K = [0x5a827999, 0x6ed9eba1, 0x8f1bbcdc, 0xca62c1d6];
|
|
20
|
+
const H = [0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0];
|
|
21
|
+
const newBytes = new Uint8Array(bytes.length + 1);
|
|
22
|
+
newBytes.set(bytes);
|
|
23
|
+
newBytes[bytes.length] = 0x80;
|
|
24
|
+
bytes = newBytes;
|
|
25
|
+
const l = bytes.length / 4 + 2;
|
|
26
|
+
const N = Math.ceil(l / 16);
|
|
27
|
+
const M = new Array(N);
|
|
28
|
+
for (let i = 0; i < N; ++i) {
|
|
29
|
+
const arr = new Uint32Array(16);
|
|
30
|
+
for (let j = 0; j < 16; ++j) {
|
|
31
|
+
arr[j] =
|
|
32
|
+
(bytes[i * 64 + j * 4] << 24) |
|
|
33
|
+
(bytes[i * 64 + j * 4 + 1] << 16) |
|
|
34
|
+
(bytes[i * 64 + j * 4 + 2] << 8) |
|
|
35
|
+
bytes[i * 64 + j * 4 + 3];
|
|
36
|
+
}
|
|
37
|
+
M[i] = arr;
|
|
38
|
+
}
|
|
39
|
+
M[N - 1][14] = ((bytes.length - 1) * 8) / 2 ** 32;
|
|
40
|
+
M[N - 1][14] = Math.floor(M[N - 1][14]);
|
|
41
|
+
M[N - 1][15] = ((bytes.length - 1) * 8) & 0xffffffff;
|
|
42
|
+
for (let i = 0; i < N; ++i) {
|
|
43
|
+
const W = new Uint32Array(80);
|
|
44
|
+
for (let t = 0; t < 16; ++t) {
|
|
45
|
+
W[t] = M[i][t];
|
|
46
|
+
}
|
|
47
|
+
for (let t = 16; t < 80; ++t) {
|
|
48
|
+
W[t] = ROTL(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
|
|
49
|
+
}
|
|
50
|
+
let a = H[0];
|
|
51
|
+
let b = H[1];
|
|
52
|
+
let c = H[2];
|
|
53
|
+
let d = H[3];
|
|
54
|
+
let e = H[4];
|
|
55
|
+
for (let t = 0; t < 80; ++t) {
|
|
56
|
+
const s = Math.floor(t / 20);
|
|
57
|
+
const T = (ROTL(a, 5) + f(s, b, c, d) + e + K[s] + W[t]) >>> 0;
|
|
58
|
+
e = d;
|
|
59
|
+
d = c;
|
|
60
|
+
c = ROTL(b, 30) >>> 0;
|
|
61
|
+
b = a;
|
|
62
|
+
a = T;
|
|
63
|
+
}
|
|
64
|
+
H[0] = (H[0] + a) >>> 0;
|
|
65
|
+
H[1] = (H[1] + b) >>> 0;
|
|
66
|
+
H[2] = (H[2] + c) >>> 0;
|
|
67
|
+
H[3] = (H[3] + d) >>> 0;
|
|
68
|
+
H[4] = (H[4] + e) >>> 0;
|
|
69
|
+
}
|
|
70
|
+
// Note: Uint8Array.of() does `& 0xff` for each value
|
|
71
|
+
return Uint8Array.of(H[0] >> 24, H[0] >> 16, H[0] >> 8, H[0], H[1] >> 24, H[1] >> 16, H[1] >> 8, H[1], H[2] >> 24, H[2] >> 16, H[2] >> 8, H[2], H[3] >> 24, H[3] >> 16, H[3] >> 8, H[3], H[4] >> 24, H[4] >> 16, H[4] >> 8, H[4]);
|
|
72
|
+
}
|
|
73
|
+
export default sha1;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.unsafeStringify = unsafeStringify;
|
|
7
|
+
const validate_js_1 = __importDefault(require("./validate.cjs"));
|
|
8
|
+
/**
|
|
9
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
10
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
11
|
+
*/
|
|
12
|
+
const byteToHex = [];
|
|
13
|
+
for (let i = 0; i < 256; ++i) {
|
|
14
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
15
|
+
}
|
|
16
|
+
function unsafeStringify(arr, offset = 0) {
|
|
17
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
18
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
19
|
+
//
|
|
20
|
+
// Note to future-self: No, you can't remove the `toLowerCase()` call.
|
|
21
|
+
// REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
|
|
22
|
+
return (byteToHex[arr[offset + 0]] +
|
|
23
|
+
byteToHex[arr[offset + 1]] +
|
|
24
|
+
byteToHex[arr[offset + 2]] +
|
|
25
|
+
byteToHex[arr[offset + 3]] +
|
|
26
|
+
"-" +
|
|
27
|
+
byteToHex[arr[offset + 4]] +
|
|
28
|
+
byteToHex[arr[offset + 5]] +
|
|
29
|
+
"-" +
|
|
30
|
+
byteToHex[arr[offset + 6]] +
|
|
31
|
+
byteToHex[arr[offset + 7]] +
|
|
32
|
+
"-" +
|
|
33
|
+
byteToHex[arr[offset + 8]] +
|
|
34
|
+
byteToHex[arr[offset + 9]] +
|
|
35
|
+
"-" +
|
|
36
|
+
byteToHex[arr[offset + 10]] +
|
|
37
|
+
byteToHex[arr[offset + 11]] +
|
|
38
|
+
byteToHex[arr[offset + 12]] +
|
|
39
|
+
byteToHex[arr[offset + 13]] +
|
|
40
|
+
byteToHex[arr[offset + 14]] +
|
|
41
|
+
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
42
|
+
}
|
|
43
|
+
function stringify(arr, offset = 0) {
|
|
44
|
+
const uuid = unsafeStringify(arr, offset);
|
|
45
|
+
// Consistency check for valid UUID. If this throws, it's likely due to one
|
|
46
|
+
// of the following:
|
|
47
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
48
|
+
// "undefined" in the uuid)
|
|
49
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
50
|
+
if (!(0, validate_js_1.default)(uuid)) {
|
|
51
|
+
throw TypeError("Stringified UUID is invalid");
|
|
52
|
+
}
|
|
53
|
+
return uuid;
|
|
54
|
+
}
|
|
55
|
+
exports.default = stringify;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import validate from "./validate.js";
|
|
2
|
+
/**
|
|
3
|
+
* Convert array of 16 byte values to UUID string format of the form:
|
|
4
|
+
* XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX
|
|
5
|
+
*/
|
|
6
|
+
const byteToHex = [];
|
|
7
|
+
for (let i = 0; i < 256; ++i) {
|
|
8
|
+
byteToHex.push((i + 0x100).toString(16).slice(1));
|
|
9
|
+
}
|
|
10
|
+
export function unsafeStringify(arr, offset = 0) {
|
|
11
|
+
// Note: Be careful editing this code! It's been tuned for performance
|
|
12
|
+
// and works in ways you may not expect. See https://github.com/uuidjs/uuid/pull/434
|
|
13
|
+
//
|
|
14
|
+
// Note to future-self: No, you can't remove the `toLowerCase()` call.
|
|
15
|
+
// REF: https://github.com/uuidjs/uuid/pull/677#issuecomment-1757351351
|
|
16
|
+
return (byteToHex[arr[offset + 0]] +
|
|
17
|
+
byteToHex[arr[offset + 1]] +
|
|
18
|
+
byteToHex[arr[offset + 2]] +
|
|
19
|
+
byteToHex[arr[offset + 3]] +
|
|
20
|
+
"-" +
|
|
21
|
+
byteToHex[arr[offset + 4]] +
|
|
22
|
+
byteToHex[arr[offset + 5]] +
|
|
23
|
+
"-" +
|
|
24
|
+
byteToHex[arr[offset + 6]] +
|
|
25
|
+
byteToHex[arr[offset + 7]] +
|
|
26
|
+
"-" +
|
|
27
|
+
byteToHex[arr[offset + 8]] +
|
|
28
|
+
byteToHex[arr[offset + 9]] +
|
|
29
|
+
"-" +
|
|
30
|
+
byteToHex[arr[offset + 10]] +
|
|
31
|
+
byteToHex[arr[offset + 11]] +
|
|
32
|
+
byteToHex[arr[offset + 12]] +
|
|
33
|
+
byteToHex[arr[offset + 13]] +
|
|
34
|
+
byteToHex[arr[offset + 14]] +
|
|
35
|
+
byteToHex[arr[offset + 15]]).toLowerCase();
|
|
36
|
+
}
|
|
37
|
+
function stringify(arr, offset = 0) {
|
|
38
|
+
const uuid = unsafeStringify(arr, offset);
|
|
39
|
+
// Consistency check for valid UUID. If this throws, it's likely due to one
|
|
40
|
+
// of the following:
|
|
41
|
+
// - One or more input array values don't map to a hex octet (leading to
|
|
42
|
+
// "undefined" in the uuid)
|
|
43
|
+
// - Invalid input values for the RFC `version` or `variant` fields
|
|
44
|
+
if (!validate(uuid)) {
|
|
45
|
+
throw TypeError("Stringified UUID is invalid");
|
|
46
|
+
}
|
|
47
|
+
return uuid;
|
|
48
|
+
}
|
|
49
|
+
export default stringify;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type UUIDTypes<TBuf extends Uint8Array = Uint8Array> = string | TBuf;
|
|
2
|
+
export type Version1Options = {
|
|
3
|
+
node?: Uint8Array;
|
|
4
|
+
clockseq?: number;
|
|
5
|
+
random?: Uint8Array;
|
|
6
|
+
rng?: () => Uint8Array;
|
|
7
|
+
msecs?: number;
|
|
8
|
+
nsecs?: number;
|
|
9
|
+
_v6?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export type Version4Options = {
|
|
12
|
+
random?: Uint8Array;
|
|
13
|
+
rng?: () => Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
export type Version6Options = Version1Options;
|
|
16
|
+
export type Version7Options = {
|
|
17
|
+
random?: Uint8Array;
|
|
18
|
+
msecs?: number;
|
|
19
|
+
seq?: number;
|
|
20
|
+
rng?: () => Uint8Array;
|
|
21
|
+
};
|
|
22
|
+
export type NonSharedArrayBuffer = ReturnType<typeof Uint8Array.of>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.URL = exports.DNS = void 0;
|
|
7
|
+
exports.stringToBytes = stringToBytes;
|
|
8
|
+
exports.default = v35;
|
|
9
|
+
const parse_js_1 = __importDefault(require("./parse.cjs"));
|
|
10
|
+
const stringify_js_1 = require("./stringify.cjs");
|
|
11
|
+
function stringToBytes(str) {
|
|
12
|
+
// TODO: Use TextEncoder (see https://stackoverflow.com/a/48762658/109538)
|
|
13
|
+
str = unescape(encodeURIComponent(str));
|
|
14
|
+
const bytes = new Uint8Array(str.length);
|
|
15
|
+
for (let i = 0; i < str.length; ++i) {
|
|
16
|
+
bytes[i] = str.charCodeAt(i);
|
|
17
|
+
}
|
|
18
|
+
return bytes;
|
|
19
|
+
}
|
|
20
|
+
exports.DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
21
|
+
exports.URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
|
22
|
+
function v35(version, hash, value, namespace, buf, offset) {
|
|
23
|
+
const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
|
|
24
|
+
const namespaceBytes = typeof namespace === "string" ? (0, parse_js_1.default)(namespace) : namespace;
|
|
25
|
+
if (typeof namespace === "string") {
|
|
26
|
+
namespace = (0, parse_js_1.default)(namespace);
|
|
27
|
+
}
|
|
28
|
+
if (namespace?.length !== 16) {
|
|
29
|
+
throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
|
|
30
|
+
}
|
|
31
|
+
// Compute hash of namespace and value, Per 4.3
|
|
32
|
+
// Future: Use spread syntax when supported on all platforms, e.g. `bytes =
|
|
33
|
+
// hashfunc([...namespace, ... value])`
|
|
34
|
+
let bytes = new Uint8Array(16 + valueBytes.length);
|
|
35
|
+
bytes.set(namespaceBytes);
|
|
36
|
+
bytes.set(valueBytes, namespaceBytes.length);
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
38
|
+
bytes = hash(bytes);
|
|
39
|
+
bytes[6] = (bytes[6] & 0x0f) | version;
|
|
40
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
41
|
+
if (buf) {
|
|
42
|
+
offset ??= 0;
|
|
43
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
44
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
45
|
+
}
|
|
46
|
+
for (let i = 0; i < 16; ++i) {
|
|
47
|
+
buf[offset + i] = bytes[i];
|
|
48
|
+
}
|
|
49
|
+
return buf;
|
|
50
|
+
}
|
|
51
|
+
return (0, stringify_js_1.unsafeStringify)(bytes);
|
|
52
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { UUIDTypes } from "./types.js";
|
|
2
|
+
export declare function stringToBytes(str: string): Uint8Array<ArrayBuffer>;
|
|
3
|
+
export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
4
|
+
export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
|
5
|
+
type HashFunction = (bytes: Uint8Array) => Uint8Array;
|
|
6
|
+
export default function v35<TBuf extends Uint8Array = Uint8Array>(version: 0x30 | 0x50, hash: HashFunction, value: string | Uint8Array, namespace: UUIDTypes, buf?: TBuf, offset?: number): UUIDTypes<TBuf>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import parse from "./parse.js";
|
|
2
|
+
import { unsafeStringify } from "./stringify.js";
|
|
3
|
+
export function stringToBytes(str) {
|
|
4
|
+
// TODO: Use TextEncoder (see https://stackoverflow.com/a/48762658/109538)
|
|
5
|
+
str = unescape(encodeURIComponent(str));
|
|
6
|
+
const bytes = new Uint8Array(str.length);
|
|
7
|
+
for (let i = 0; i < str.length; ++i) {
|
|
8
|
+
bytes[i] = str.charCodeAt(i);
|
|
9
|
+
}
|
|
10
|
+
return bytes;
|
|
11
|
+
}
|
|
12
|
+
export const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
|
|
13
|
+
export const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
|
|
14
|
+
export default function v35(version, hash, value, namespace, buf, offset) {
|
|
15
|
+
const valueBytes = typeof value === "string" ? stringToBytes(value) : value;
|
|
16
|
+
const namespaceBytes = typeof namespace === "string" ? parse(namespace) : namespace;
|
|
17
|
+
if (typeof namespace === "string") {
|
|
18
|
+
namespace = parse(namespace);
|
|
19
|
+
}
|
|
20
|
+
if (namespace?.length !== 16) {
|
|
21
|
+
throw TypeError("Namespace must be array-like (16 iterable integer values, 0-255)");
|
|
22
|
+
}
|
|
23
|
+
// Compute hash of namespace and value, Per 4.3
|
|
24
|
+
// Future: Use spread syntax when supported on all platforms, e.g. `bytes =
|
|
25
|
+
// hashfunc([...namespace, ... value])`
|
|
26
|
+
let bytes = new Uint8Array(16 + valueBytes.length);
|
|
27
|
+
bytes.set(namespaceBytes);
|
|
28
|
+
bytes.set(valueBytes, namespaceBytes.length);
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
30
|
+
bytes = hash(bytes);
|
|
31
|
+
bytes[6] = (bytes[6] & 0x0f) | version;
|
|
32
|
+
bytes[8] = (bytes[8] & 0x3f) | 0x80;
|
|
33
|
+
if (buf) {
|
|
34
|
+
offset ??= 0;
|
|
35
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
36
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
37
|
+
}
|
|
38
|
+
for (let i = 0; i < 16; ++i) {
|
|
39
|
+
buf[offset + i] = bytes[i];
|
|
40
|
+
}
|
|
41
|
+
return buf;
|
|
42
|
+
}
|
|
43
|
+
return unsafeStringify(bytes);
|
|
44
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const rng_js_1 = __importDefault(require("./rng.cjs"));
|
|
7
|
+
const stringify_js_1 = require("./stringify.cjs");
|
|
8
|
+
function v4(options, buf, offset) {
|
|
9
|
+
if (!buf && !options && crypto.randomUUID) {
|
|
10
|
+
return crypto.randomUUID();
|
|
11
|
+
}
|
|
12
|
+
// Putting tail-code that could just go inline here in a separate function to
|
|
13
|
+
// enable compiler optimizations that dramatically improve performance.
|
|
14
|
+
//
|
|
15
|
+
// REF: https://github.com/uuidjs/uuid/issues/892
|
|
16
|
+
return _v4(options, buf, offset);
|
|
17
|
+
}
|
|
18
|
+
function _v4(options, buf, offset) {
|
|
19
|
+
options = options || {};
|
|
20
|
+
const rnds = options.random ?? options.rng?.() ?? (0, rng_js_1.default)();
|
|
21
|
+
if (rnds.length < 16) {
|
|
22
|
+
throw new Error("Random bytes length must be >= 16");
|
|
23
|
+
}
|
|
24
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
25
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
26
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
27
|
+
// Copy bytes to buffer, if provided
|
|
28
|
+
if (buf) {
|
|
29
|
+
offset = offset || 0;
|
|
30
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
31
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
32
|
+
}
|
|
33
|
+
for (let i = 0; i < 16; ++i) {
|
|
34
|
+
buf[offset + i] = rnds[i];
|
|
35
|
+
}
|
|
36
|
+
return buf;
|
|
37
|
+
}
|
|
38
|
+
return (0, stringify_js_1.unsafeStringify)(rnds);
|
|
39
|
+
}
|
|
40
|
+
exports.default = v4;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Version4Options } from "./types.js";
|
|
2
|
+
declare function v4(options?: Version4Options, buf?: undefined, offset?: number): string;
|
|
3
|
+
declare function v4<TBuf extends Uint8Array = Uint8Array>(options: Version4Options | undefined, buf: TBuf, offset?: number): TBuf;
|
|
4
|
+
export default v4;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import rng from "./rng.js";
|
|
2
|
+
import { unsafeStringify } from "./stringify.js";
|
|
3
|
+
function v4(options, buf, offset) {
|
|
4
|
+
if (!buf && !options && crypto.randomUUID) {
|
|
5
|
+
return crypto.randomUUID();
|
|
6
|
+
}
|
|
7
|
+
// Putting tail-code that could just go inline here in a separate function to
|
|
8
|
+
// enable compiler optimizations that dramatically improve performance.
|
|
9
|
+
//
|
|
10
|
+
// REF: https://github.com/uuidjs/uuid/issues/892
|
|
11
|
+
return _v4(options, buf, offset);
|
|
12
|
+
}
|
|
13
|
+
function _v4(options, buf, offset) {
|
|
14
|
+
options = options || {};
|
|
15
|
+
const rnds = options.random ?? options.rng?.() ?? rng();
|
|
16
|
+
if (rnds.length < 16) {
|
|
17
|
+
throw new Error("Random bytes length must be >= 16");
|
|
18
|
+
}
|
|
19
|
+
// Per 4.4, set bits for version and `clock_seq_hi_and_reserved`
|
|
20
|
+
rnds[6] = (rnds[6] & 0x0f) | 0x40;
|
|
21
|
+
rnds[8] = (rnds[8] & 0x3f) | 0x80;
|
|
22
|
+
// Copy bytes to buffer, if provided
|
|
23
|
+
if (buf) {
|
|
24
|
+
offset = offset || 0;
|
|
25
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
26
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
27
|
+
}
|
|
28
|
+
for (let i = 0; i < 16; ++i) {
|
|
29
|
+
buf[offset + i] = rnds[i];
|
|
30
|
+
}
|
|
31
|
+
return buf;
|
|
32
|
+
}
|
|
33
|
+
return unsafeStringify(rnds);
|
|
34
|
+
}
|
|
35
|
+
export default v4;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.URL = exports.DNS = void 0;
|
|
40
|
+
const sha1_js_1 = __importDefault(require("./sha1.cjs"));
|
|
41
|
+
const v35_js_1 = __importStar(require("./v35.cjs"));
|
|
42
|
+
var v35_js_2 = require("./v35.cjs");
|
|
43
|
+
Object.defineProperty(exports, "DNS", { enumerable: true, get: function () { return v35_js_2.DNS; } });
|
|
44
|
+
Object.defineProperty(exports, "URL", { enumerable: true, get: function () { return v35_js_2.URL; } });
|
|
45
|
+
function v5(value, namespace, buf, offset) {
|
|
46
|
+
return (0, v35_js_1.default)(0x50, sha1_js_1.default, value, namespace, buf, offset);
|
|
47
|
+
}
|
|
48
|
+
v5.DNS = v35_js_1.DNS;
|
|
49
|
+
v5.URL = v35_js_1.URL;
|
|
50
|
+
exports.default = v5;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { UUIDTypes } from "./types.js";
|
|
2
|
+
export { DNS, URL } from "./v35.js";
|
|
3
|
+
declare function v5(value: string | Uint8Array, namespace: UUIDTypes, buf?: undefined, offset?: number): string;
|
|
4
|
+
declare function v5<TBuf extends Uint8Array = Uint8Array>(value: string | Uint8Array, namespace: UUIDTypes, buf: TBuf, offset?: number): TBuf;
|
|
5
|
+
declare namespace v5 {
|
|
6
|
+
var DNS: string;
|
|
7
|
+
var URL: string;
|
|
8
|
+
}
|
|
9
|
+
export default v5;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import sha1 from "./sha1.js";
|
|
2
|
+
import v35, { DNS, URL } from "./v35.js";
|
|
3
|
+
export { DNS, URL } from "./v35.js";
|
|
4
|
+
function v5(value, namespace, buf, offset) {
|
|
5
|
+
return v35(0x50, sha1, value, namespace, buf, offset);
|
|
6
|
+
}
|
|
7
|
+
v5.DNS = DNS;
|
|
8
|
+
v5.URL = URL;
|
|
9
|
+
export default v5;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.updateV7State = updateV7State;
|
|
7
|
+
const rng_js_1 = __importDefault(require("./rng.cjs"));
|
|
8
|
+
const stringify_js_1 = require("./stringify.cjs");
|
|
9
|
+
const _state = {};
|
|
10
|
+
function v7(options, buf, offset) {
|
|
11
|
+
let bytes;
|
|
12
|
+
if (options) {
|
|
13
|
+
// With options: Make UUID independent of internal state
|
|
14
|
+
bytes = v7Bytes(options.random ?? options.rng?.() ?? (0, rng_js_1.default)(), options.msecs, options.seq, buf, offset);
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
// No options: Use internal state
|
|
18
|
+
const now = Date.now();
|
|
19
|
+
const rnds = (0, rng_js_1.default)();
|
|
20
|
+
updateV7State(_state, now, rnds);
|
|
21
|
+
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
|
22
|
+
}
|
|
23
|
+
return buf ?? (0, stringify_js_1.unsafeStringify)(bytes);
|
|
24
|
+
}
|
|
25
|
+
// (Private!) Do not use. This method is only exported for testing purposes
|
|
26
|
+
// and may change without notice.
|
|
27
|
+
function updateV7State(state, now, rnds) {
|
|
28
|
+
state.msecs ??= -Infinity;
|
|
29
|
+
state.seq ??= 0;
|
|
30
|
+
if (now > state.msecs) {
|
|
31
|
+
// Time has moved on! Pick a new random sequence number
|
|
32
|
+
state.seq = (rnds[6] << 23) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
33
|
+
state.msecs = now;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
// Bump sequence counter w/ 32-bit rollover
|
|
37
|
+
state.seq = (state.seq + 1) | 0;
|
|
38
|
+
// In case of rollover, bump timestamp to preserve monotonicity. This is
|
|
39
|
+
// allowed by the RFC and should self-correct as the system clock catches
|
|
40
|
+
// up. See https://www.rfc-editor.org/rfc/rfc9562.html#section-6.2-9.4
|
|
41
|
+
if (state.seq === 0) {
|
|
42
|
+
state.msecs++;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
return state;
|
|
46
|
+
}
|
|
47
|
+
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
48
|
+
if (rnds.length < 16) {
|
|
49
|
+
throw new Error("Random bytes length must be >= 16");
|
|
50
|
+
}
|
|
51
|
+
if (!buf) {
|
|
52
|
+
buf = new Uint8Array(16);
|
|
53
|
+
offset = 0;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
57
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Defaults
|
|
61
|
+
msecs ??= Date.now();
|
|
62
|
+
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
63
|
+
// byte 0-5: timestamp (48 bits)
|
|
64
|
+
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
|
65
|
+
buf[offset++] = (msecs / 0x100000000) & 0xff;
|
|
66
|
+
buf[offset++] = (msecs / 0x1000000) & 0xff;
|
|
67
|
+
buf[offset++] = (msecs / 0x10000) & 0xff;
|
|
68
|
+
buf[offset++] = (msecs / 0x100) & 0xff;
|
|
69
|
+
buf[offset++] = msecs & 0xff;
|
|
70
|
+
// byte 6: `version` (4 bits) | sequence bits 28-31 (4 bits)
|
|
71
|
+
buf[offset++] = 0x70 | ((seq >>> 28) & 0x0f);
|
|
72
|
+
// byte 7: sequence bits 20-27 (8 bits)
|
|
73
|
+
buf[offset++] = (seq >>> 20) & 0xff;
|
|
74
|
+
// byte 8: `variant` (2 bits) | sequence bits 14-19 (6 bits)
|
|
75
|
+
buf[offset++] = 0x80 | ((seq >>> 14) & 0x3f);
|
|
76
|
+
// byte 9: sequence bits 6-13 (8 bits)
|
|
77
|
+
buf[offset++] = (seq >>> 6) & 0xff;
|
|
78
|
+
// byte 10: sequence bits 0-5 (6 bits) | random (2 bits)
|
|
79
|
+
buf[offset++] = ((seq << 2) & 0xff) | (rnds[10] & 0x03);
|
|
80
|
+
// bytes 11-15: random (40 bits)
|
|
81
|
+
buf[offset++] = rnds[11];
|
|
82
|
+
buf[offset++] = rnds[12];
|
|
83
|
+
buf[offset++] = rnds[13];
|
|
84
|
+
buf[offset++] = rnds[14];
|
|
85
|
+
buf[offset++] = rnds[15];
|
|
86
|
+
return buf;
|
|
87
|
+
}
|
|
88
|
+
exports.default = v7;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Version7Options } from "./types.js";
|
|
2
|
+
type V7State = {
|
|
3
|
+
msecs?: number;
|
|
4
|
+
seq?: number;
|
|
5
|
+
};
|
|
6
|
+
declare function v7(options?: Version7Options, buf?: undefined, offset?: number): string;
|
|
7
|
+
declare function v7<TBuf extends Uint8Array = Uint8Array>(options: Version7Options | undefined, buf: TBuf, offset?: number): TBuf;
|
|
8
|
+
export declare function updateV7State(state: V7State, now: number, rnds: Uint8Array): V7State;
|
|
9
|
+
export default v7;
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import rng from "./rng.js";
|
|
2
|
+
import { unsafeStringify } from "./stringify.js";
|
|
3
|
+
const _state = {};
|
|
4
|
+
function v7(options, buf, offset) {
|
|
5
|
+
let bytes;
|
|
6
|
+
if (options) {
|
|
7
|
+
// With options: Make UUID independent of internal state
|
|
8
|
+
bytes = v7Bytes(options.random ?? options.rng?.() ?? rng(), options.msecs, options.seq, buf, offset);
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
// No options: Use internal state
|
|
12
|
+
const now = Date.now();
|
|
13
|
+
const rnds = rng();
|
|
14
|
+
updateV7State(_state, now, rnds);
|
|
15
|
+
bytes = v7Bytes(rnds, _state.msecs, _state.seq, buf, offset);
|
|
16
|
+
}
|
|
17
|
+
return buf ?? unsafeStringify(bytes);
|
|
18
|
+
}
|
|
19
|
+
// (Private!) Do not use. This method is only exported for testing purposes
|
|
20
|
+
// and may change without notice.
|
|
21
|
+
export function updateV7State(state, now, rnds) {
|
|
22
|
+
state.msecs ??= -Infinity;
|
|
23
|
+
state.seq ??= 0;
|
|
24
|
+
if (now > state.msecs) {
|
|
25
|
+
// Time has moved on! Pick a new random sequence number
|
|
26
|
+
state.seq = (rnds[6] << 23) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
27
|
+
state.msecs = now;
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// Bump sequence counter w/ 32-bit rollover
|
|
31
|
+
state.seq = (state.seq + 1) | 0;
|
|
32
|
+
// In case of rollover, bump timestamp to preserve monotonicity. This is
|
|
33
|
+
// allowed by the RFC and should self-correct as the system clock catches
|
|
34
|
+
// up. See https://www.rfc-editor.org/rfc/rfc9562.html#section-6.2-9.4
|
|
35
|
+
if (state.seq === 0) {
|
|
36
|
+
state.msecs++;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return state;
|
|
40
|
+
}
|
|
41
|
+
function v7Bytes(rnds, msecs, seq, buf, offset = 0) {
|
|
42
|
+
if (rnds.length < 16) {
|
|
43
|
+
throw new Error("Random bytes length must be >= 16");
|
|
44
|
+
}
|
|
45
|
+
if (!buf) {
|
|
46
|
+
buf = new Uint8Array(16);
|
|
47
|
+
offset = 0;
|
|
48
|
+
}
|
|
49
|
+
else {
|
|
50
|
+
if (offset < 0 || offset + 16 > buf.length) {
|
|
51
|
+
throw new RangeError(`UUID byte range ${offset}:${offset + 15} is out of buffer bounds`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// Defaults
|
|
55
|
+
msecs ??= Date.now();
|
|
56
|
+
seq ??= ((rnds[6] * 0x7f) << 24) | (rnds[7] << 16) | (rnds[8] << 8) | rnds[9];
|
|
57
|
+
// byte 0-5: timestamp (48 bits)
|
|
58
|
+
buf[offset++] = (msecs / 0x10000000000) & 0xff;
|
|
59
|
+
buf[offset++] = (msecs / 0x100000000) & 0xff;
|
|
60
|
+
buf[offset++] = (msecs / 0x1000000) & 0xff;
|
|
61
|
+
buf[offset++] = (msecs / 0x10000) & 0xff;
|
|
62
|
+
buf[offset++] = (msecs / 0x100) & 0xff;
|
|
63
|
+
buf[offset++] = msecs & 0xff;
|
|
64
|
+
// byte 6: `version` (4 bits) | sequence bits 28-31 (4 bits)
|
|
65
|
+
buf[offset++] = 0x70 | ((seq >>> 28) & 0x0f);
|
|
66
|
+
// byte 7: sequence bits 20-27 (8 bits)
|
|
67
|
+
buf[offset++] = (seq >>> 20) & 0xff;
|
|
68
|
+
// byte 8: `variant` (2 bits) | sequence bits 14-19 (6 bits)
|
|
69
|
+
buf[offset++] = 0x80 | ((seq >>> 14) & 0x3f);
|
|
70
|
+
// byte 9: sequence bits 6-13 (8 bits)
|
|
71
|
+
buf[offset++] = (seq >>> 6) & 0xff;
|
|
72
|
+
// byte 10: sequence bits 0-5 (6 bits) | random (2 bits)
|
|
73
|
+
buf[offset++] = ((seq << 2) & 0xff) | (rnds[10] & 0x03);
|
|
74
|
+
// bytes 11-15: random (40 bits)
|
|
75
|
+
buf[offset++] = rnds[11];
|
|
76
|
+
buf[offset++] = rnds[12];
|
|
77
|
+
buf[offset++] = rnds[13];
|
|
78
|
+
buf[offset++] = rnds[14];
|
|
79
|
+
buf[offset++] = rnds[15];
|
|
80
|
+
return buf;
|
|
81
|
+
}
|
|
82
|
+
export default v7;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const regex_js_1 = __importDefault(require("./regex.cjs"));
|
|
7
|
+
function validate(uuid) {
|
|
8
|
+
return typeof uuid === "string" && regex_js_1.default.test(uuid);
|
|
9
|
+
}
|
|
10
|
+
exports.default = validate;
|