@anizoptera/uuid-slug 0.3.0 → 0.4.0
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/LICENSE +54 -31
- package/README.md +1052 -261
- package/dist/alphabet.d.ts +5 -17
- package/dist/alphabet.d.ts.map +1 -1
- package/dist/alphabet.js +146 -112
- package/dist/alphabet.js.map +1 -1
- package/dist/base64url-name.d.ts +7 -0
- package/dist/base64url-name.d.ts.map +1 -0
- package/dist/base64url-name.js +8 -0
- package/dist/base64url-name.js.map +1 -0
- package/dist/errors.d.ts +50 -9
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +145 -63
- package/dist/errors.js.map +1 -1
- package/dist/feistel.js +29 -95
- package/dist/feistel.js.map +1 -1
- package/dist/generation-options.js +20 -0
- package/dist/generation-options.js.map +1 -0
- package/dist/index.d.ts +22 -10
- package/dist/index.js +21 -9
- package/dist/instant.js +83 -0
- package/dist/instant.js.map +1 -0
- package/dist/mask-handle.d.ts +16 -0
- package/dist/mask-handle.d.ts.map +1 -0
- package/dist/mask-handle.js +60 -0
- package/dist/mask-handle.js.map +1 -0
- package/dist/mask.d.ts +27 -0
- package/dist/mask.d.ts.map +1 -0
- package/dist/mask.js +151 -95
- package/dist/mask.js.map +1 -1
- package/dist/masking-codec-protocol.js +23 -0
- package/dist/masking-codec-protocol.js.map +1 -0
- package/dist/masking-codec-types.d.ts +245 -0
- package/dist/masking-codec-types.d.ts.map +1 -0
- package/dist/masking-codec.d.ts +19 -0
- package/dist/masking-codec.d.ts.map +1 -0
- package/dist/masking-codec.js +391 -0
- package/dist/masking-codec.js.map +1 -0
- package/dist/migration.js +114 -51
- package/dist/migration.js.map +1 -1
- package/dist/node/runtime.js +39 -0
- package/dist/node/runtime.js.map +1 -0
- package/dist/payload.d.ts +7 -0
- package/dist/payload.d.ts.map +1 -0
- package/dist/payload.js +118 -0
- package/dist/payload.js.map +1 -0
- package/dist/runtime/pool.js +21 -46
- package/dist/runtime/pool.js.map +1 -1
- package/dist/runtime/portable.js +27 -0
- package/dist/runtime/portable.js.map +1 -0
- package/dist/sentinel.js +10 -0
- package/dist/sentinel.js.map +1 -0
- package/dist/siphash.js +20 -99
- package/dist/siphash.js.map +1 -1
- package/dist/slug.d.ts +169 -0
- package/dist/slug.d.ts.map +1 -0
- package/dist/slug.js +268 -0
- package/dist/slug.js.map +1 -0
- package/dist/timestamp.d.ts +19 -0
- package/dist/timestamp.d.ts.map +1 -0
- package/dist/timestamp.js +44 -0
- package/dist/timestamp.js.map +1 -0
- package/dist/types.d.ts +480 -200
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/dist/uuid-value-protocol.js +46 -0
- package/dist/uuid-value-protocol.js.map +1 -0
- package/dist/uuid-value.d.ts +17 -0
- package/dist/uuid-value.d.ts.map +1 -0
- package/dist/uuid-value.js +127 -0
- package/dist/uuid-value.js.map +1 -0
- package/dist/uuid.d.ts +51 -64
- package/dist/uuid.d.ts.map +1 -1
- package/dist/uuid.js +203 -199
- package/dist/uuid.js.map +1 -1
- package/dist/v4-slug.d.ts +16 -0
- package/dist/v4-slug.d.ts.map +1 -0
- package/dist/v4-slug.js +16 -0
- package/dist/v4-slug.js.map +1 -0
- package/dist/v4.d.ts +42 -0
- package/dist/v4.d.ts.map +1 -0
- package/dist/v4.js +85 -0
- package/dist/v4.js.map +1 -0
- package/dist/v7-bounds.d.ts +36 -0
- package/dist/v7-bounds.d.ts.map +1 -0
- package/dist/v7-bounds.js +49 -0
- package/dist/v7-bounds.js.map +1 -0
- package/dist/v7-generator-input.js +75 -0
- package/dist/v7-generator-input.js.map +1 -0
- package/dist/v7-generator.d.ts +43 -0
- package/dist/v7-generator.d.ts.map +1 -0
- package/dist/v7-generator.js +105 -0
- package/dist/v7-generator.js.map +1 -0
- package/dist/v7-keyless.d.ts +46 -0
- package/dist/v7-keyless.d.ts.map +1 -0
- package/dist/v7-keyless.js +106 -0
- package/dist/v7-keyless.js.map +1 -0
- package/dist/v7-payload.js +54 -0
- package/dist/v7-payload.js.map +1 -0
- package/dist/v7-slug.d.ts +46 -0
- package/dist/v7-slug.d.ts.map +1 -0
- package/dist/v7-slug.js +127 -0
- package/dist/v7-slug.js.map +1 -0
- package/dist/v7-timestamp.js +9 -0
- package/dist/v7-timestamp.js.map +1 -0
- package/dist/v7-value-options.js +28 -0
- package/dist/v7-value-options.js.map +1 -0
- package/dist/v7-value.d.ts +23 -0
- package/dist/v7-value.d.ts.map +1 -0
- package/dist/v7-value.js +31 -0
- package/dist/v7-value.js.map +1 -0
- package/dist/v7.js +127 -171
- package/dist/v7.js.map +1 -1
- package/package.json +14 -9
- package/src/alphabet.ts +456 -27
- package/src/base64url-name.ts +5 -0
- package/src/errors.ts +373 -37
- package/src/feistel.ts +69 -56
- package/src/generation-options.ts +48 -0
- package/src/index.ts +134 -80
- package/src/instant.ts +196 -0
- package/src/keyless.ts +7 -134
- package/src/mask-handle.ts +141 -0
- package/src/mask.ts +354 -129
- package/src/masking-codec-protocol.ts +29 -0
- package/src/masking-codec-types.ts +380 -0
- package/src/masking-codec.ts +923 -0
- package/src/migration.ts +195 -42
- package/src/payload.ts +321 -0
- package/src/runtime/bun.ts +30 -49
- package/src/runtime/node.ts +43 -24
- package/src/runtime/pool.ts +49 -21
- package/src/runtime/portable.ts +68 -0
- package/src/runtime/types.ts +23 -35
- package/src/sentinel.ts +13 -0
- package/src/siphash.ts +5 -4
- package/src/slug.ts +884 -0
- package/src/timestamp.ts +122 -0
- package/src/types.ts +759 -205
- package/src/uuid-value-protocol.ts +77 -0
- package/src/uuid-value.ts +341 -0
- package/src/uuid.ts +514 -234
- package/src/v4-slug.ts +27 -0
- package/src/v4.ts +234 -0
- package/src/v7-bounds.ts +171 -0
- package/src/v7-generator-input.ts +169 -0
- package/src/v7-generator.ts +245 -0
- package/src/v7-keyless.ts +354 -0
- package/src/v7-payload.ts +121 -0
- package/src/v7-slug.ts +293 -0
- package/src/v7-timestamp.ts +21 -0
- package/src/v7-value-options.ts +62 -0
- package/src/v7-value.ts +54 -0
- package/src/v7.ts +377 -200
- package/dist/base64url.d.ts +0 -20
- package/dist/base64url.d.ts.map +0 -1
- package/dist/base64url.js +0 -33
- package/dist/base64url.js.map +0 -1
- package/dist/codec.d.ts +0 -17
- package/dist/codec.d.ts.map +0 -1
- package/dist/codec.js +0 -192
- package/dist/codec.js.map +0 -1
- package/dist/keyless.d.ts +0 -31
- package/dist/keyless.d.ts.map +0 -1
- package/dist/keyless.js +0 -93
- package/dist/keyless.js.map +0 -1
- package/dist/legacy-mask.js +0 -55
- package/dist/legacy-mask.js.map +0 -1
- package/dist/node/alphabet.js +0 -130
- package/dist/node/base64url.js +0 -31
- package/dist/node/codec.js +0 -190
- package/dist/node/errors.js +0 -78
- package/dist/node/feistel.js +0 -103
- package/dist/node/index.js +0 -10
- package/dist/node/keyless.js +0 -91
- package/dist/node/legacy-mask.js +0 -53
- package/dist/node/mask.js +0 -106
- package/dist/node/migration.js +0 -64
- package/dist/node/runtime/node.js +0 -33
- package/dist/node/runtime/pool.js +0 -53
- package/dist/node/schema.js +0 -214
- package/dist/node/siphash.js +0 -106
- package/dist/node/uuid.js +0 -226
- package/dist/node/v7.js +0 -185
- package/dist/node/yield.js +0 -20
- package/dist/runtime/web.js +0 -39
- package/dist/runtime/web.js.map +0 -1
- package/dist/schema.d.ts +0 -20
- package/dist/schema.d.ts.map +0 -1
- package/dist/schema.js +0 -216
- package/dist/schema.js.map +0 -1
- package/dist/v7.d.ts +0 -12
- package/dist/v7.d.ts.map +0 -1
- package/dist/yield.js +0 -22
- package/dist/yield.js.map +0 -1
- package/src/base64url.ts +0 -41
- package/src/codec.ts +0 -320
- package/src/legacy-mask.ts +0 -25
- package/src/runtime/web.ts +0 -48
- package/src/schema.ts +0 -300
- package/src/yield.ts +0 -22
package/dist/v7.js
CHANGED
|
@@ -1,187 +1,143 @@
|
|
|
1
1
|
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// @anizoptera/uuid-slug 0.
|
|
3
|
-
import { UuidSlugError, checkRange, fillRandomBytes, readClock } from "./errors.js";
|
|
4
|
-
import {
|
|
2
|
+
// @anizoptera/uuid-slug 0.4.0 | https://github.com/Anizoptera/uuid-slug#readme
|
|
3
|
+
import { INVALID_TIMESTAMP as e, RNG_UNAVAILABLE as t, UuidSlugError as n, checkByteRange as r, checkRange as i, diagnosticValue as a, fillRandomBytes as o, isUint8Array as s, isUuidSlugError as c, readClock as l, stringInput as u } from "./errors.js";
|
|
4
|
+
import { readGenerationOptions as d } from "./generation-options.js";
|
|
5
|
+
import { UUID_TEXT_LOWERCASE as f } from "./types.js";
|
|
6
|
+
import { MAX_UUID_V7_UNIX_MS as p, isValidUuidV7UnixMs as m } from "./v7-timestamp.js";
|
|
7
|
+
import { readUuidV7Instant as h } from "./instant.js";
|
|
8
|
+
import { formatUuidBytesUnchecked as g, resolveUuidTextCase as _ } from "./uuid.js";
|
|
5
9
|
//#region src/v7.ts
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const v = {
|
|
11
|
+
at: !0,
|
|
12
|
+
textCase: !0
|
|
13
|
+
}, y = {
|
|
14
|
+
at: !0,
|
|
15
|
+
output: !0,
|
|
16
|
+
outputOffset: !0
|
|
17
|
+
};
|
|
18
|
+
function writeTimestampWords(e, t, n) {
|
|
19
|
+
let r = Math.floor(t / 4294967296);
|
|
20
|
+
e[n] = r >>> 8, e[n + 1] = r, e[n + 2] = t >>> 24, e[n + 3] = t >>> 16, e[n + 4] = t >>> 8, e[n + 5] = t;
|
|
21
|
+
}
|
|
22
|
+
function writeTimestampLoop(e, t, n) {
|
|
23
|
+
let r = t;
|
|
24
|
+
for (let t = 5; t >= 0; --t) e[n + t] = r & 255, r = Math.floor(r / 256);
|
|
12
25
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
* The sequence is carried as a 10-bit high half and a 32-bit low half rather than one 42-bit
|
|
18
|
-
* BigInt, so every operation here is a 32-bit integer op the JIT emits directly. Measured on the
|
|
19
|
-
* increment-and-write step alone: 9.99M ops/s (Bun) and 11.8M (Node) as a BigInt, against 252M
|
|
20
|
-
* and 149M in this form. The bit layout is unchanged, so the ids are identical either way.
|
|
21
|
-
*/
|
|
22
|
-
function writeCounter(bytes, hi, lo, offset) {
|
|
23
|
-
bytes[offset + 6] = 112 | hi >>> 6 & 15;
|
|
24
|
-
bytes[offset + 7] = ((hi & 63) << 2 | lo >>> 30) & 255;
|
|
25
|
-
bytes[offset + 8] = 128 | lo >>> 24 & 63;
|
|
26
|
-
bytes[offset + 9] = lo >>> 16 & 255;
|
|
27
|
-
bytes[offset + 10] = lo >>> 8 & 255;
|
|
28
|
-
bytes[offset + 11] = lo & 255;
|
|
26
|
+
const b = globalThis.Bun ? writeTimestampLoop : writeTimestampWords;
|
|
27
|
+
function writeCounter(e, t, n, r) {
|
|
28
|
+
e[r + 6] = 112 | t >>> 6 & 15, e[r + 7] = ((t & 63) << 2 | n >>> 30) & 255, e[r + 8] = 128 | n >>> 24 & 63, e[r + 9] = n >>> 16 & 255, e[r + 10] = n >>> 8 & 255, e[r + 11] = n & 255;
|
|
29
29
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*/
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const rejectInstant = (ms) => isValidUuidV7Timestamp(ms) ? void 0 : new UuidSlugError("invalid_timestamp", `UUIDv7 timestamp must be a whole number of milliseconds in 0..${MAX_TIMESTAMP}.`);
|
|
47
|
-
/**
|
|
48
|
-
* Both string forms differ only in where the instant comes from, so the byte-or-error result is
|
|
49
|
-
* carried through here rather than unwrapped twice. The narrowing is an assertion because
|
|
50
|
-
* `formatUuid` is version-agnostic: the v7-ness is established by the caller having produced the
|
|
51
|
-
* bytes, not by anything the formatter can check.
|
|
52
|
-
*/
|
|
53
|
-
const formatUuidV7 = (result) => result instanceof Error ? result : formatUuid(result);
|
|
54
|
-
/**
|
|
55
|
-
* Seeds the sequence from the same six random bytes and the same bit positions as before, split
|
|
56
|
-
* across the two halves: byte 0 and the top 2 bits of byte 1 form the high half, the rest the
|
|
57
|
-
* low half. Starting each millisecond at a random point rather than zero is what stops the
|
|
58
|
-
* sequence leaking how many ids were issued in the previous millisecond.
|
|
59
|
-
*/
|
|
60
|
-
const seedHi = (bytes) => ((bytes[0] ?? 0) << 2 | (bytes[1] ?? 0) >>> 6) & 1023;
|
|
61
|
-
const seedLo = (bytes) => (((bytes[1] ?? 0) & 63) << 26 | (bytes[2] ?? 0) << 18 | (bytes[3] ?? 0) << 10 | (bytes[4] ?? 0) << 2 | (bytes[5] ?? 0) & 3) >>> 0;
|
|
62
|
-
function createUuidV7Generator(options) {
|
|
63
|
-
const clock = options.clock ?? Date.now;
|
|
64
|
-
const fill = options.fillRandom;
|
|
65
|
-
const random = /* @__PURE__ */ new Uint8Array(16);
|
|
66
|
-
/**
|
|
67
|
-
* Below every timestamp the clock check admits, which is what makes it the uninitialised
|
|
68
|
-
* sentinel rather than a value: `now > lastMs` alone therefore takes the reseed branch on the
|
|
69
|
-
* first call, and no separate "have we started" flag is needed. The coupling is deliberate and
|
|
70
|
-
* is why the clock is validated before this is compared against — an unvalidated clock returning
|
|
71
|
-
* a negative millisecond would make `lastMs` stay below it forever, so the monotonic counter
|
|
72
|
-
* would never be used and every call would reseed.
|
|
73
|
-
*/
|
|
74
|
-
let lastMs = -1;
|
|
75
|
-
let counterHi = 0;
|
|
76
|
-
let counterLo = 0;
|
|
77
|
-
function reseed(ms) {
|
|
78
|
-
const failed = fillRandomBytes(fill, random);
|
|
79
|
-
if (failed) return failed;
|
|
80
|
-
lastMs = ms;
|
|
81
|
-
counterHi = seedHi(random);
|
|
82
|
-
counterLo = seedLo(random);
|
|
30
|
+
const formatUuidV7 = /* @__NO_SIDE_EFFECTS__ */ (e, t, n) => e === n ? /* @__PURE__ */ g(n, 0, t) : e, reenteredGeneration = /* @__NO_SIDE_EFFECTS__ */ () => new n(t, "UUIDv7 generation cannot be reentered from its readUnixMs or entropy callback."), seedHi = /* @__NO_SIDE_EFFECTS__ */ (e) => ((e[0] ?? 0) << 2 | (e[1] ?? 0) >>> 6) & 1023, seedLo = /* @__NO_SIDE_EFFECTS__ */ (e) => (((e[1] ?? 0) & 63) << 26 | (e[2] ?? 0) << 18 | (e[3] ?? 0) << 10 | (e[4] ?? 0) << 2 | (e[5] ?? 0) & 3) >>> 0;
|
|
31
|
+
function createPortableUuidV7Generator(t) {
|
|
32
|
+
let x = t.readUnixMs ?? Date.now, S = t.fillRandom, C = t.clockRollback, w = t.subMillisecondFractionBits ?? 0, T = t.coordinateExplicitInstants ?? !0, E = 42 - w, D = 2 ** E, O = Object.freeze({
|
|
33
|
+
subMillisecondFractionBits: w,
|
|
34
|
+
counterBits: E
|
|
35
|
+
}), k = /* @__PURE__ */ new Uint8Array(10), A = k.subarray(6), j = -1, M = -1, N = 0, P = 0, F = !1, I = t.textScratch ?? /* @__PURE__ */ new Uint8Array(16);
|
|
36
|
+
function reseed(e, t) {
|
|
37
|
+
let n = o(S, k);
|
|
38
|
+
if (n) return n;
|
|
39
|
+
let r = (/* @__PURE__ */ seedHi(k) * 4294967296 + /* @__PURE__ */ seedLo(k)) % D, i = t * D + r;
|
|
40
|
+
j = e, N = Math.floor(i / 4294967296), P = i >>> 0;
|
|
41
|
+
}
|
|
42
|
+
function writeBytes(e, t, n, r, i) {
|
|
43
|
+
b(e, n, t), writeCounter(e, r, i, t);
|
|
44
|
+
for (let n = 12; n < 16; n += 1) e[t + n] = A[n - 12];
|
|
45
|
+
return e;
|
|
83
46
|
}
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
if (
|
|
92
|
-
|
|
93
|
-
if (
|
|
94
|
-
const failed = fillRandomBytes(fill, random);
|
|
95
|
-
if (failed) return failed;
|
|
96
|
-
ms = timestamp;
|
|
97
|
-
sequenceHi = seedHi(random);
|
|
98
|
-
sequenceLo = seedLo(random);
|
|
47
|
+
function advanceSequence(t, r) {
|
|
48
|
+
let i = C === void 0 ? 0 : M - t;
|
|
49
|
+
if (C !== void 0 && i > C.toleranceMs) {
|
|
50
|
+
if (C.action === "error") return new n(e, `Clock moved backward by ${i} milliseconds; clockRollback allows ${C.toleranceMs}. Increase tolerance or choose reset/preserve if this rollback is acceptable.`);
|
|
51
|
+
let a = reseed(t, r);
|
|
52
|
+
if (a) return a;
|
|
53
|
+
M = t;
|
|
54
|
+
} else if (t > j || t === j && r > Math.floor((N * 4294967296 + P) / D)) {
|
|
55
|
+
let e = reseed(t, r);
|
|
56
|
+
if (e) return e;
|
|
99
57
|
} else {
|
|
100
|
-
|
|
101
|
-
if (
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
const failed = reseed(now);
|
|
106
|
-
if (failed) return failed;
|
|
58
|
+
let t = P + 1 >>> 0, r = N + +(t === 0);
|
|
59
|
+
if (r > 1023) {
|
|
60
|
+
if (j >= 0xffffffffffff) return new n(e, `UUIDv7 sequence exhausted at Unix millisecond ${p}; another UUID would exceed the 48-bit timestamp.`);
|
|
61
|
+
let t = reseed(j + 1, 0);
|
|
62
|
+
if (t) return t;
|
|
107
63
|
} else {
|
|
108
|
-
|
|
109
|
-
if (
|
|
110
|
-
|
|
111
|
-
if (lastMs >= MAX_TIMESTAMP) return new UuidSlugError("invalid_timestamp", `Sequence exhausted at the last representable millisecond (${MAX_TIMESTAMP}).`);
|
|
112
|
-
const failed = reseed(lastMs + 1);
|
|
113
|
-
if (failed) return failed;
|
|
114
|
-
} else {
|
|
115
|
-
const failed = fillRandomBytes(fill, random);
|
|
116
|
-
if (failed) return failed;
|
|
117
|
-
}
|
|
64
|
+
let e = o(S, A);
|
|
65
|
+
if (e) return e;
|
|
66
|
+
P = t, N = r;
|
|
118
67
|
}
|
|
119
|
-
ms = lastMs;
|
|
120
|
-
sequenceHi = counterHi;
|
|
121
|
-
sequenceLo = counterLo;
|
|
122
68
|
}
|
|
123
|
-
|
|
124
|
-
writeCounter(target, sequenceHi, sequenceLo, offset);
|
|
125
|
-
for (let i = 12; i < 16; i += 1) target[offset + i] = random[i];
|
|
126
|
-
return target;
|
|
69
|
+
C !== void 0 && t > M && (M = t);
|
|
127
70
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
71
|
+
function bytes(o, s = 0) {
|
|
72
|
+
if (F) return /* @__PURE__ */ reenteredGeneration();
|
|
73
|
+
F = !0;
|
|
74
|
+
try {
|
|
75
|
+
let u = o ?? /* @__PURE__ */ new Uint8Array(16), d = u === I ? void 0 : o === void 0 ? s === 0 ? void 0 : /* @__PURE__ */ i(16, s, 16) : /* @__PURE__ */ r(o, s, 16);
|
|
76
|
+
if (d) return d;
|
|
77
|
+
let f = l(x);
|
|
78
|
+
if (/* @__PURE__ */ c(f)) return f;
|
|
79
|
+
let h = typeof f == "number" ? Math.trunc(f) : NaN;
|
|
80
|
+
return typeof f != "number" || f < 0 || !/* @__PURE__ */ m(h) ? new n(e, `Clock returned ${a(f)}, which is not a millisecond in 0..${p}.`) : advanceSequence(h, w === 0 ? 0 : t.readFractionBucket12 === void 0 ? Math.min(2 ** w - 1, Math.floor((f - h) * 2 ** w)) : t.readFractionBucket12() >>> 12 - w) || writeBytes(u, s, j, N, P);
|
|
81
|
+
} finally {
|
|
82
|
+
F = !1;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function bytesAt(e, t, n = 0) {
|
|
86
|
+
if (F) return /* @__PURE__ */ reenteredGeneration();
|
|
87
|
+
F = !0;
|
|
88
|
+
try {
|
|
89
|
+
let a = t ?? /* @__PURE__ */ new Uint8Array(16), s = t === void 0 ? n === 0 ? void 0 : /* @__PURE__ */ i(16, n, 16) : /* @__PURE__ */ r(t, n, 16);
|
|
90
|
+
if (s) return s;
|
|
91
|
+
let c = w === 0 ? 0 : e.fractionBucket12 >>> 12 - w;
|
|
92
|
+
if (T) return advanceSequence(e.unixMs, c) || writeBytes(a, n, j, N, P);
|
|
93
|
+
let l = o(S, k);
|
|
94
|
+
if (l) return l;
|
|
95
|
+
let u = (/* @__PURE__ */ seedHi(k) * 4294967296 + /* @__PURE__ */ seedLo(k)) % D, d = c * D + u;
|
|
96
|
+
return writeBytes(a, n, e.unixMs, Math.floor(d / 4294967296), d >>> 0);
|
|
97
|
+
} finally {
|
|
98
|
+
F = !1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function generateUuidV7Bytes(e, t) {
|
|
102
|
+
if (e === void 0 || /* @__PURE__ */ s(e)) return bytes(e, t);
|
|
103
|
+
if (Array.isArray(e) || ArrayBuffer.isView(e)) return /* @__PURE__ */ r(e, t ?? 0, 16);
|
|
104
|
+
let n = d(e, y, "UUIDv7 byte generation");
|
|
105
|
+
if (n instanceof Error) return n;
|
|
106
|
+
let i = n.output, a = n.outputOffset;
|
|
107
|
+
if (!Object.hasOwn(n, "at")) return bytes(i, a);
|
|
108
|
+
let o = h(n.at);
|
|
109
|
+
return o instanceof Error ? o : bytesAt(o, i, a);
|
|
110
|
+
}
|
|
111
|
+
function drawUuidV7Bytes(e, t, n) {
|
|
112
|
+
return e === void 0 ? bytes(t, n) : bytesAt(e, t, n);
|
|
113
|
+
}
|
|
114
|
+
function generateUuidV7(e = f) {
|
|
115
|
+
if (typeof e == "string") {
|
|
116
|
+
let t = _(e);
|
|
117
|
+
if (t instanceof Error) return t;
|
|
118
|
+
let n = bytes(I);
|
|
119
|
+
return n === I ? /* @__PURE__ */ g(I, 0, t) : n;
|
|
120
|
+
}
|
|
121
|
+
let t = d(e, v, "UUIDv7 generation");
|
|
122
|
+
if (t instanceof Error) {
|
|
123
|
+
let n = /* @__PURE__ */ u(e);
|
|
124
|
+
n !== void 0 && (t = { textCase: n });
|
|
181
125
|
}
|
|
126
|
+
if (t instanceof Error) return t;
|
|
127
|
+
let n = _(t.textCase ?? "lowercase");
|
|
128
|
+
if (n instanceof Error) return n;
|
|
129
|
+
if (!Object.hasOwn(t, "at")) return /* @__PURE__ */ formatUuidV7(bytes(I), n, I);
|
|
130
|
+
let r = h(t.at);
|
|
131
|
+
return r instanceof Error ? r : /* @__PURE__ */ formatUuidV7(bytesAt(r, I), n, I);
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
payloadLayout: O,
|
|
135
|
+
generateUuidV7,
|
|
136
|
+
generateUuidV7Bytes,
|
|
137
|
+
drawUuidV7Bytes
|
|
182
138
|
};
|
|
183
139
|
}
|
|
184
140
|
//#endregion
|
|
185
|
-
export {
|
|
141
|
+
export { createPortableUuidV7Generator };
|
|
186
142
|
|
|
187
143
|
//# sourceMappingURL=v7.js.map
|
package/dist/v7.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v7.js","names":[],"sources":["../src/v7.ts"],"sourcesContent":["// SPDX-License-Identifier: Apache-2.0\n\nimport { checkRange, fillRandomBytes, readClock, UuidSlugError } from \"./errors\";\nimport type { UuidV7Generator, UuidV7String } from \"./types\";\nimport { formatUuid } from \"./uuid\";\nimport type { Runtime } from \"./runtime/types\";\n\nexport interface UuidV7GeneratorOptions {\n readonly clock?: () => number;\n readonly fillRandom: (bytes: Uint8Array<ArrayBuffer>) => void;\n}\n\nfunction writeTimestamp(bytes: Uint8Array, ms: number, offset: number) {\n let value = Math.trunc(ms);\n for (let i = 5; i >= 0; i -= 1) {\n bytes[offset + i] = value & 0xff;\n value = Math.floor(value / 256);\n }\n}\n\n/**\n * Writes the 42-bit sequence RFC 9562 §6.2 allows in `rand_a` plus the top of `rand_b`, along\n * with the version and variant bits that bracket it.\n *\n * The sequence is carried as a 10-bit high half and a 32-bit low half rather than one 42-bit\n * BigInt, so every operation here is a 32-bit integer op the JIT emits directly. Measured on the\n * increment-and-write step alone: 9.99M ops/s (Bun) and 11.8M (Node) as a BigInt, against 252M\n * and 149M in this form. The bit layout is unchanged, so the ids are identical either way.\n */\nfunction writeCounter(bytes: Uint8Array, hi: number, lo: number, offset: number) {\n bytes[offset + 6] = 0x70 | ((hi >>> 6) & 0x0f);\n bytes[offset + 7] = (((hi & 0x3f) << 2) | (lo >>> 30)) & 0xff;\n bytes[offset + 8] = 0x80 | ((lo >>> 24) & 0x3f);\n bytes[offset + 9] = (lo >>> 16) & 0xff;\n bytes[offset + 10] = (lo >>> 8) & 0xff;\n bytes[offset + 11] = lo & 0xff;\n}\n\n/** The 48 bits RFC 9562 gives the timestamp; beyond it the value cannot be represented. */\nconst MAX_TIMESTAMP = 0xffff_ffff_ffff;\n\n/**\n * `Number.isInteger` rather than `isFinite`, because the error message promises a WHOLE number of\n * milliseconds and `Math.trunc` on the write path would otherwise honour that promise silently:\n * 1.5 became 1 with nothing reported. It also rejects NaN and Infinity, which matters because a\n * native generator need not — measured 2026-08-12, `Bun.randomUUIDv7(\"hex\", NaN)` and the same\n * call at 2^48 both return the 1970 prefix `000000000000` without throwing, while -1 and 1.5 do\n * throw. Validating here rather than trusting the platform is what makes the two agree.\n */\nconst isValidUuidV7Timestamp = (ms: number): boolean =>\n Number.isInteger(ms) && ms >= 0 && ms <= MAX_TIMESTAMP;\n\n/**\n * The one check and the one message for a caller-supplied instant. Both the portable generator and\n * the runtime-backed one call it, and the runtime-backed one calls it BEFORE delegating: a native\n * generator may accept what we reject and answer wrongly rather than fail.\n */\nconst rejectInstant = (ms: number): UuidSlugError | undefined =>\n isValidUuidV7Timestamp(ms)\n ? undefined\n : new UuidSlugError(\n \"invalid_timestamp\",\n `UUIDv7 timestamp must be a whole number of milliseconds in 0..${MAX_TIMESTAMP}.`,\n );\n\n/**\n * Both string forms differ only in where the instant comes from, so the byte-or-error result is\n * carried through here rather than unwrapped twice. The narrowing is an assertion because\n * `formatUuid` is version-agnostic: the v7-ness is established by the caller having produced the\n * bytes, not by anything the formatter can check.\n */\nconst formatUuidV7 = (result: UuidSlugError | Uint8Array): UuidSlugError | UuidV7String =>\n result instanceof Error ? result : (formatUuid(result) as UuidSlugError | UuidV7String);\n\n/**\n * Seeds the sequence from the same six random bytes and the same bit positions as before, split\n * across the two halves: byte 0 and the top 2 bits of byte 1 form the high half, the rest the\n * low half. Starting each millisecond at a random point rather than zero is what stops the\n * sequence leaking how many ids were issued in the previous millisecond.\n */\nconst seedHi = (bytes: Uint8Array) => (((bytes[0] ?? 0) << 2) | ((bytes[1] ?? 0) >>> 6)) & 0x3ff;\n\nconst seedLo = (bytes: Uint8Array) =>\n ((((bytes[1] ?? 0) & 0x3f) << 26) |\n ((bytes[2] ?? 0) << 18) |\n ((bytes[3] ?? 0) << 10) |\n ((bytes[4] ?? 0) << 2) |\n ((bytes[5] ?? 0) & 0x03)) >>>\n 0;\n\nexport function createUuidV7Generator(options: UuidV7GeneratorOptions): UuidV7Generator {\n const clock = options.clock ?? Date.now;\n const fill = options.fillRandom;\n const random = new Uint8Array(16);\n /**\n * Below every timestamp the clock check admits, which is what makes it the uninitialised\n * sentinel rather than a value: `now > lastMs` alone therefore takes the reseed branch on the\n * first call, and no separate \"have we started\" flag is needed. The coupling is deliberate and\n * is why the clock is validated before this is compared against — an unvalidated clock returning\n * a negative millisecond would make `lastMs` stay below it forever, so the monotonic counter\n * would never be used and every call would reseed.\n */\n let lastMs = -1;\n let counterHi = 0;\n let counterLo = 0;\n\n function reseed(ms: number) {\n const failed = fillRandomBytes(fill, random);\n if (failed) return failed;\n lastMs = ms;\n counterHi = seedHi(random);\n counterLo = seedLo(random);\n return undefined;\n }\n\n function bytes(\n out?: Uint8Array,\n offset = 0,\n timestamp?: number,\n explicit = false,\n ): UuidSlugError | Uint8Array {\n const target = out ?? new Uint8Array(16);\n const badRange = checkRange(target.length, offset, 16);\n if (badRange) return badRange;\n // The two modes differ only in where the millisecond and the 42-bit sequence come from, so\n // they share one write path. A caller-supplied instant takes a RANDOM sequence rather than\n // the monotonic counter, and leaves `lastMs`/`counter` untouched: that counter orders values\n // issued inside the CURRENT millisecond, and a caller naming an arbitrary instant is not\n // extending that sequence. Feeding a supplied timestamp through it would be worse than\n // useless — an older instant fails the `now > lastMs` test and the value would carry the\n // clock's millisecond instead of the requested one.\n let ms: number;\n let sequenceHi: number;\n let sequenceLo: number;\n if (explicit) {\n const invalid = rejectInstant(timestamp as number);\n if (invalid) return invalid;\n const failed = fillRandomBytes(fill, random);\n if (failed) return failed;\n ms = timestamp as number;\n sequenceHi = seedHi(random);\n sequenceLo = seedLo(random);\n } else {\n // Truncated THEN validated, in that order and not the other. A clock is allowed to be\n // fractional — `performance.timeOrigin + performance.now()` is, and is a perfectly good one —\n // so rejecting non-integers here would refuse a legitimate caller, unlike `rejectInstant`,\n // where the fraction is in an argument the caller wrote out. What must not survive is a\n // truncated value the format cannot carry: `writeTimestamp` keeps the low 48 bits of whatever\n // it is handed, so NaN and 2**48 both silently produced the 1970 prefix and a negative\n // millisecond produced the year 10889 by two's-complement wrap. All three now report.\n // The raw reading is kept for the message rather than calling `clock()` again: a second call\n // is a second reading, and the message would name a value other than the one refused.\n const reading = readClock(clock);\n if (reading instanceof Error) return reading;\n const now = Math.trunc(reading);\n if (reading < 0 || !isValidUuidV7Timestamp(now))\n return new UuidSlugError(\n \"invalid_timestamp\",\n `Clock returned ${String(reading)}, which is not a millisecond in 0..${MAX_TIMESTAMP}.`,\n );\n if (now > lastMs) {\n const failed = reseed(now);\n if (failed) return failed;\n } else {\n counterLo = (counterLo + 1) >>> 0;\n if (counterLo === 0) counterHi += 1;\n // Past 42 bits the sequence no longer fits `rand_a` plus the borrowed `rand_b` bits.\n // Borrowing the next millisecond keeps ids ordered and unique rather than wrapping into\n // values this millisecond has already issued.\n if (counterHi > 0x3ff) {\n // At the ceiling there is no next millisecond to borrow: `writeTimestamp` truncates to\n // six bytes, so `lastMs + 1` wraps to 0 and the generator restarts in 1970 — ordering\n // broken permanently, and silently, from that call onward. Unreachable on a real clock\n // until the year 10889; reachable now from any clock that lands near the ceiling, which\n // is why refusing is not theoretical.\n if (lastMs >= MAX_TIMESTAMP)\n return new UuidSlugError(\n \"invalid_timestamp\",\n `Sequence exhausted at the last representable millisecond (${MAX_TIMESTAMP}).`,\n );\n const failed = reseed(lastMs + 1);\n if (failed) return failed;\n } else {\n const failed = fillRandomBytes(fill, random);\n if (failed) return failed;\n }\n }\n ms = lastMs;\n sequenceHi = counterHi;\n sequenceLo = counterLo;\n }\n // The checked offset applies to every store. Write directly into the target so callers\n // reusing an output buffer also avoid allocating a temporary typed-array view.\n writeTimestamp(target, ms, offset);\n writeCounter(target, sequenceHi, sequenceLo, offset);\n for (let i = 12; i < 16; i += 1) target[offset + i] = random[i] as number;\n return target;\n }\n\n return {\n uuidV7() {\n const formatted = formatUuidV7(bytes());\n // Throws rather than returns, because this signature promises a string: the two ways it can\n // fail — entropy, and a `clock` that returns something the format cannot carry — are both\n // configuration the caller cannot act on per call. `uuidV7At` returns its Error instead,\n // because there the failure is a value the caller passed in at the call site.\n if (formatted instanceof Error) throw formatted;\n return formatted;\n },\n uuidV7At: (timestamp) => formatUuidV7(bytes(undefined, 0, timestamp, true)),\n uuidV7Bytes: (out, offset) => bytes(out, offset),\n uuidV7BytesAt: (timestamp, out, offset) => bytes(out, offset, timestamp, true),\n };\n}\n\nexport function createRuntimeGenerator(runtime: Runtime): UuidV7Generator {\n const fallback = createUuidV7Generator({ fillRandom: runtime.fillRandom });\n return {\n uuidV7() {\n if (!runtime.uuidV7) return fallback.uuidV7();\n try {\n return runtime.uuidV7();\n } catch {\n return fallback.uuidV7();\n }\n },\n // The range is checked BEFORE delegating for the same reason the instant is: a native writer\n // is handed the caller's buffer and offset directly, and answers differently from the portable\n // path. Measured on Bun 1.3.14, `out.set(bytes, offset)` coerces a NaN offset to 0 and writes\n // at the wrong place reporting success, while a fractional one throws a RangeError that the\n // catch below would relabel `rng_unavailable` — blaming the entropy source for a caller's\n // argument. Checking here is what makes every runtime give the one answer.\n uuidV7Bytes(out?: Uint8Array, offset = 0) {\n // Guarded only on the branch that leaves this package: the fallback checks the same range\n // itself, so checking before the branch would pay for it twice on every Node call.\n if (!runtime.uuidV7Bytes) return fallback.uuidV7Bytes(out, offset);\n const badRange = checkRange(out?.length ?? 16, offset, 16);\n if (badRange) return badRange;\n try {\n return runtime.uuidV7Bytes(out, offset);\n } catch (cause) {\n return new UuidSlugError(\"rng_unavailable\", \"Runtime UUIDv7 byte generation failed.\", {\n cause,\n });\n }\n },\n // Both timestamped paths reject the instant BEFORE reaching the platform, because a native\n // generator that accepts it may answer wrongly instead of failing: measured 2026-08-12,\n // `Bun.randomUUIDv7(\"hex\", NaN)` and the same call at 2^48 both return the 1970 prefix\n // `000000000000` silently, while -1 and 1.5 throw. Each then mirrors its untimestamped\n // sibling on a platform failure — fall back for the string form, report for the byte form —\n // so the four entry points behave predictably in pairs.\n uuidV7At(timestamp: number) {\n if (!runtime.uuidV7At) return fallback.uuidV7At(timestamp);\n const invalid = rejectInstant(timestamp);\n if (invalid) return invalid;\n try {\n return runtime.uuidV7At(timestamp);\n } catch {\n return fallback.uuidV7At(timestamp);\n }\n },\n uuidV7BytesAt(timestamp: number, out?: Uint8Array, offset = 0) {\n if (!runtime.uuidV7BytesAt) return fallback.uuidV7BytesAt(timestamp, out, offset);\n const invalid = rejectInstant(timestamp);\n if (invalid) return invalid;\n const badRange = checkRange(out?.length ?? 16, offset, 16);\n if (badRange) return badRange;\n try {\n return runtime.uuidV7BytesAt(timestamp, out, offset);\n } catch (cause) {\n return new UuidSlugError(\"rng_unavailable\", \"Runtime UUIDv7 byte generation failed.\", {\n cause,\n });\n }\n },\n };\n}\n"],"mappings":";;;;;AAYA,SAAS,eAAe,OAAmB,IAAY,QAAgB;CACrE,IAAI,QAAQ,KAAK,MAAM,EAAE;CACzB,KAAK,IAAI,IAAI,GAAG,KAAK,GAAG,KAAK,GAAG;EAC9B,MAAM,SAAS,KAAK,QAAQ;EAC5B,QAAQ,KAAK,MAAM,QAAQ,GAAG;CAChC;AACF;;;;;;;;;;AAWA,SAAS,aAAa,OAAmB,IAAY,IAAY,QAAgB;CAC/E,MAAM,SAAS,KAAK,MAAS,OAAO,IAAK;CACzC,MAAM,SAAS,OAAQ,KAAK,OAAS,IAAM,OAAO,MAAO;CACzD,MAAM,SAAS,KAAK,MAAS,OAAO,KAAM;CAC1C,MAAM,SAAS,KAAM,OAAO,KAAM;CAClC,MAAM,SAAS,MAAO,OAAO,IAAK;CAClC,MAAM,SAAS,MAAM,KAAK;AAC5B;;AAGA,MAAM,gBAAgB;;;;;;;;;AAUtB,MAAM,0BAA0B,OAC9B,OAAO,UAAU,EAAE,KAAK,MAAM,KAAK,MAAM;;;;;;AAO3C,MAAM,iBAAiB,OACrB,uBAAuB,EAAE,IACrB,KAAA,IACA,IAAI,cACF,qBACA,iEAAiE,cAAc,EACjF;;;;;;;AAQN,MAAM,gBAAgB,WACp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Y,KAAK,MAAM;GACjE,MAAM,WAAW,WAAW,KAAK,UAAU,IAAI,QAAQ,EAAE;GACzD,IAAI,UAAU,OAAO;GACrB,IAAI;IACF,OAAO,QAAQ,YAAY,KAAK,MAAM;GACxC,SAAS,OAAO;IACd,OAAO,IAAI,cAAc,mBAAmB,0CAA0C,EACpF,MACF,CAAC;GACH;EACF;EAOA,SAAS,WAAmB;GAC1B,IAAI,CAAC,QAAQ,UAAU,OAAO,SAAS,SAAS,SAAS;GACzD,MAAM,UAAU,cAAc,SAAS;GACvC,IAAI,SAAS,OAAO;GACpB,IAAI;IACF,OAAO,QAAQ,SAAS,SAAS;GACnC,QAAQ;IACN,OAAO,SAAS,SAAS,SAAS;GACpC;EACF;EACA,cAAc,WAAmB,KAAkB,SAAS,GAAG;GAC7D,IAAI,CAAC,QAAQ,eAAe,OAAO,SAAS,cAAc,WAAW,KAAK,MAAM;GAChF,MAAM,UAAU,cAAc,SAAS;GACvC,IAAI,SAAS,OAAO;GACpB,MAAM,WAAW,WAAW,KAAK,UAAU,IAAI,QAAQ,EAAE;GACzD,IAAI,UAAU,OAAO;GACrB,IAAI;IACF,OAAO,QAAQ,cAAc,WAAW,KAAK,MAAM;GACrD,SAAS,OAAO;IACd,OAAO,IAAI,cAAc,mBAAmB,0CAA0C,EACpF,MACF,CAAC;GACH;EACF;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"v7.js","names":["UUID_V7_TEXT_OPTIONS","UUID_V7_BYTE_OPTIONS","high","ms","offset","value","index","writeTimestamp","hi","lo","result","output","textCase","UuidSlugError","RNG_UNAVAILABLE","bytes","readUnixMs","options","fill","rollback","fractionBits","coordinateExplicitInstants","counterBits","counterModulus","payloadLayout","random","randomTail","lastMs","clockHighWaterMs","counterHi","counterLo","generating","textBytes","failed","fillRandomBytes","seededCounter","payloadPrefix","fraction","target","sequenceHi","sequenceLo","i","rollbackMs","now","INVALID_TIMESTAMP","nextLo","nextHi","MAX_UUID_V7_UNIX_MS","out","badRange","reading","readClock","diagnosticValue","instant","outOrOptions","values","readGenerationOptions","outputOffset","readUuidV7Instant","UUID_TEXT_LOWERCASE","textCaseOrOptions","resolveUuidTextCase","wrappedCase"],"sources":["../src/v7.ts"],"mappings":";;;;;;;;;AAwEA,MAAMA,IAAuB;CAC3B,IAAI;CACJ,UAAU;AACZ,GACMC,IAAuB;CAC3B,IAAI;CACJ,QAAQ;CACR,cAAc;AAChB;AAMA,SAAS,oBAAoB,GAAmB,GAAY,GAAgB;CAG1E,IAAMC,IAAO,KAAK,MAAMC,IAAK,UAAa;CAM1C,AALA,EAAMC,KAAUF,MAAS,GACzB,EAAME,IAAS,KAAKF,GACpB,EAAME,IAAS,KAAKD,MAAO,IAC3B,EAAMC,IAAS,KAAKD,MAAO,IAC3B,EAAMC,IAAS,KAAKD,MAAO,GAC3B,EAAMC,IAAS,KAAKD;AACtB;AAEA,SAAS,mBAAmB,GAAmB,GAAY,GAAgB;CACzE,IAAIE,IAAQF;CACZ,KAAK,IAAIG,IAAQ,GAAGA,KAAS,GAAG,KAE9B,AADA,EAAMF,IAASE,KAASD,IAAQ,KAChC,IAAQ,KAAK,MAAMA,IAAQ,GAAG;AAElC;AAIA,MAAME,IAAkB,WAAgC,MACpD,qBACA;AAWJ,SAAS,aAAa,GAAmB,GAAY,GAAY,GAAgB;CAM/E,AALA,EAAMH,IAAS,KAAK,MAASI,MAAO,IAAK,IACzC,EAAMJ,IAAS,OAAQI,IAAK,OAAS,IAAMC,MAAO,MAAO,KACzD,EAAML,IAAS,KAAK,MAASK,MAAO,KAAM,IAC1C,EAAML,IAAS,KAAMK,MAAO,KAAM,KAClC,EAAML,IAAS,MAAOK,MAAO,IAAK,KAClC,EAAML,IAAS,MAAMK,IAAK;AAC5B;AAKA,MAAM,2CACJ,GACA,GACA,MAEAC,MAAWC,IACN,kBAAyBA,GAAQ,GAAGC,CAAQ,IAC5CF,GAED,uDACJ,IAAIG,EACFC,GACA,gFACF,GAQI,qCAAqC,QACtCC,EAAM,MA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B;EAC3E,IAAI3C,aAAoB,OAAO,OAAOA;EACtC,IAAI,CAAC,OAAO,OAAO2C,GAAQ,IAAS,GAClC,OAAO,6BAAa,MAAMvB,CAAS,GAAGpB,GAAUoB,CAAS;EAC3D,IAAMqB,IAAUK,EAAkBH,EAAO,EAAE;EAC3C,OAAOF,aAAmB,QACtBA,IACC,6BAAa,QAAQA,GAASrB,CAAS,GAAGpB,GAAUoB,CAAS;CACpE;CAEA,OAAO;EAIL;EACA;EACA;EACA;CACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anizoptera/uuid-slug",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.4.0",
|
|
4
|
+
"description": "Zero-dependency UUIDv4/v7 generation, lossless base64url and base32hex slugs for any UUID, and reversible UUIDv7 masking for databases, URLs, and files.",
|
|
5
5
|
"keywords": [
|
|
6
|
+
"base32hex",
|
|
6
7
|
"base64url",
|
|
7
8
|
"browser",
|
|
8
9
|
"bun",
|
|
@@ -11,8 +12,10 @@
|
|
|
11
12
|
"node",
|
|
12
13
|
"short-uuid",
|
|
13
14
|
"slug",
|
|
15
|
+
"typescript",
|
|
14
16
|
"url-safe",
|
|
15
17
|
"uuid",
|
|
18
|
+
"uuidv4",
|
|
16
19
|
"uuidv7",
|
|
17
20
|
"zero-dependencies"
|
|
18
21
|
],
|
|
@@ -37,19 +40,21 @@
|
|
|
37
40
|
"imports": {
|
|
38
41
|
"#runtime": {
|
|
39
42
|
"bun": "./src/runtime/bun.ts",
|
|
40
|
-
"deno": "./src/runtime/
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
"deno": "./src/runtime/portable.ts",
|
|
44
|
+
"development": {
|
|
45
|
+
"node": "./src/runtime/node.ts",
|
|
46
|
+
"default": "./src/runtime/portable.ts"
|
|
47
|
+
},
|
|
48
|
+
"node": "./dist/node/runtime.js",
|
|
49
|
+
"default": "./dist/runtime/portable.js"
|
|
44
50
|
}
|
|
45
51
|
},
|
|
46
52
|
"exports": {
|
|
47
53
|
".": {
|
|
48
54
|
"types": "./dist/index.d.ts",
|
|
49
55
|
"bun": "./src/index.ts",
|
|
50
|
-
"deno": "./
|
|
51
|
-
"
|
|
52
|
-
"node": "./dist/node/index.js",
|
|
56
|
+
"deno": "./src/index.ts",
|
|
57
|
+
"development": "./src/index.ts",
|
|
53
58
|
"default": "./dist/index.js"
|
|
54
59
|
},
|
|
55
60
|
"./package.json": "./package.json"
|