@anizoptera/uuid-slug 0.2.0 → 0.3.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/README.md +381 -27
- package/dist/alphabet.d.ts +21 -0
- package/dist/alphabet.d.ts.map +1 -0
- package/dist/alphabet.js +132 -0
- package/dist/alphabet.js.map +1 -0
- package/dist/base64url.d.ts +20 -0
- package/dist/base64url.d.ts.map +1 -0
- package/dist/base64url.js +33 -0
- package/dist/base64url.js.map +1 -0
- package/dist/codec.d.ts +17 -0
- package/dist/codec.d.ts.map +1 -0
- package/dist/codec.js +192 -0
- package/dist/codec.js.map +1 -0
- package/dist/errors.d.ts +16 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +80 -0
- package/dist/errors.js.map +1 -0
- package/dist/feistel.js +105 -0
- package/dist/feistel.js.map +1 -0
- package/dist/index.d.ts +11 -168
- package/dist/index.js +10 -649
- package/dist/keyless.d.ts +31 -0
- package/dist/keyless.d.ts.map +1 -0
- package/dist/keyless.js +93 -0
- package/dist/keyless.js.map +1 -0
- package/dist/legacy-mask.js +55 -0
- package/dist/legacy-mask.js.map +1 -0
- package/dist/mask.js +108 -0
- package/dist/mask.js.map +1 -0
- package/dist/migration.js +66 -0
- package/dist/migration.js.map +1 -0
- package/dist/node/alphabet.js +130 -0
- package/dist/node/base64url.js +31 -0
- package/dist/node/codec.js +190 -0
- package/dist/node/errors.js +78 -0
- package/dist/node/feistel.js +103 -0
- package/dist/node/index.js +10 -647
- package/dist/node/keyless.js +91 -0
- package/dist/node/legacy-mask.js +53 -0
- package/dist/node/mask.js +106 -0
- package/dist/node/migration.js +64 -0
- package/dist/node/runtime/node.js +33 -0
- package/dist/node/runtime/pool.js +53 -0
- package/dist/node/schema.js +214 -0
- package/dist/node/siphash.js +106 -0
- package/dist/node/uuid.js +226 -0
- package/dist/node/v7.js +185 -0
- package/dist/node/yield.js +20 -0
- package/dist/runtime/pool.js +55 -0
- package/dist/runtime/pool.js.map +1 -0
- package/dist/runtime/web.js +39 -0
- package/dist/runtime/web.js.map +1 -0
- package/dist/schema.d.ts +20 -0
- package/dist/schema.d.ts.map +1 -0
- package/dist/schema.js +216 -0
- package/dist/schema.js.map +1 -0
- package/dist/siphash.js +108 -0
- package/dist/siphash.js.map +1 -0
- package/dist/types.d.ts +255 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/uuid.d.ts +78 -0
- package/dist/uuid.d.ts.map +1 -0
- package/dist/uuid.js +228 -0
- package/dist/uuid.js.map +1 -0
- package/dist/v7.d.ts +12 -0
- package/dist/v7.d.ts.map +1 -0
- package/dist/v7.js +187 -0
- package/dist/v7.js.map +1 -0
- package/dist/yield.js +22 -0
- package/dist/yield.js.map +1 -0
- package/package.json +8 -12
- package/src/alphabet.ts +187 -0
- package/src/base64url.ts +28 -63
- package/src/codec.ts +227 -125
- package/src/errors.ts +83 -9
- package/src/feistel.ts +128 -0
- package/src/index.ts +52 -26
- package/src/keyless.ts +136 -0
- package/src/legacy-mask.ts +25 -0
- package/src/mask.ts +129 -67
- package/src/migration.ts +104 -0
- package/src/runtime/bun.ts +49 -24
- package/src/runtime/node.ts +33 -15
- package/src/runtime/pool.ts +62 -0
- package/src/runtime/types.ts +42 -5
- package/src/runtime/web.ts +37 -9
- package/src/schema.ts +274 -97
- package/src/siphash.ts +127 -0
- package/src/types.ts +221 -37
- package/src/uuid.ts +189 -50
- package/src/v7.ts +217 -45
- package/src/yield.ts +22 -0
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/web/index.js +0 -648
package/src/v7.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
import { checkRange, fillRandomBytes, readClock, UuidSlugError } from "./errors";
|
|
2
4
|
import type { UuidV7Generator, UuidV7String } from "./types";
|
|
3
5
|
import { formatUuid } from "./uuid";
|
|
4
6
|
import type { Runtime } from "./runtime/types";
|
|
@@ -8,76 +10,206 @@ export interface UuidV7GeneratorOptions {
|
|
|
8
10
|
readonly fillRandom: (bytes: Uint8Array<ArrayBuffer>) => void;
|
|
9
11
|
}
|
|
10
12
|
|
|
11
|
-
function writeTimestamp(bytes: Uint8Array, ms: number) {
|
|
13
|
+
function writeTimestamp(bytes: Uint8Array, ms: number, offset: number) {
|
|
12
14
|
let value = Math.trunc(ms);
|
|
13
15
|
for (let i = 5; i >= 0; i -= 1) {
|
|
14
|
-
bytes[i] = value & 0xff;
|
|
16
|
+
bytes[offset + i] = value & 0xff;
|
|
15
17
|
value = Math.floor(value / 256);
|
|
16
18
|
}
|
|
17
19
|
}
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Writes the 42-bit sequence RFC 9562 §6.2 allows in `rand_a` plus the top of `rand_b`, along
|
|
23
|
+
* with the version and variant bits that bracket it.
|
|
24
|
+
*
|
|
25
|
+
* The sequence is carried as a 10-bit high half and a 32-bit low half rather than one 42-bit
|
|
26
|
+
* BigInt, so every operation here is a 32-bit integer op the JIT emits directly. Measured on the
|
|
27
|
+
* increment-and-write step alone: 9.99M ops/s (Bun) and 11.8M (Node) as a BigInt, against 252M
|
|
28
|
+
* and 149M in this form. The bit layout is unchanged, so the ids are identical either way.
|
|
29
|
+
*/
|
|
30
|
+
function writeCounter(bytes: Uint8Array, hi: number, lo: number, offset: number) {
|
|
31
|
+
bytes[offset + 6] = 0x70 | ((hi >>> 6) & 0x0f);
|
|
32
|
+
bytes[offset + 7] = (((hi & 0x3f) << 2) | (lo >>> 30)) & 0xff;
|
|
33
|
+
bytes[offset + 8] = 0x80 | ((lo >>> 24) & 0x3f);
|
|
34
|
+
bytes[offset + 9] = (lo >>> 16) & 0xff;
|
|
35
|
+
bytes[offset + 10] = (lo >>> 8) & 0xff;
|
|
36
|
+
bytes[offset + 11] = lo & 0xff;
|
|
26
37
|
}
|
|
27
38
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
/** The 48 bits RFC 9562 gives the timestamp; beyond it the value cannot be represented. */
|
|
40
|
+
const MAX_TIMESTAMP = 0xffff_ffff_ffff;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* `Number.isInteger` rather than `isFinite`, because the error message promises a WHOLE number of
|
|
44
|
+
* milliseconds and `Math.trunc` on the write path would otherwise honour that promise silently:
|
|
45
|
+
* 1.5 became 1 with nothing reported. It also rejects NaN and Infinity, which matters because a
|
|
46
|
+
* native generator need not — measured 2026-08-12, `Bun.randomUUIDv7("hex", NaN)` and the same
|
|
47
|
+
* call at 2^48 both return the 1970 prefix `000000000000` without throwing, while -1 and 1.5 do
|
|
48
|
+
* throw. Validating here rather than trusting the platform is what makes the two agree.
|
|
49
|
+
*/
|
|
50
|
+
const isValidUuidV7Timestamp = (ms: number): boolean =>
|
|
51
|
+
Number.isInteger(ms) && ms >= 0 && ms <= MAX_TIMESTAMP;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The one check and the one message for a caller-supplied instant. Both the portable generator and
|
|
55
|
+
* the runtime-backed one call it, and the runtime-backed one calls it BEFORE delegating: a native
|
|
56
|
+
* generator may accept what we reject and answer wrongly rather than fail.
|
|
57
|
+
*/
|
|
58
|
+
const rejectInstant = (ms: number): UuidSlugError | undefined =>
|
|
59
|
+
isValidUuidV7Timestamp(ms)
|
|
60
|
+
? undefined
|
|
61
|
+
: new UuidSlugError(
|
|
62
|
+
"invalid_timestamp",
|
|
63
|
+
`UUIDv7 timestamp must be a whole number of milliseconds in 0..${MAX_TIMESTAMP}.`,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Both string forms differ only in where the instant comes from, so the byte-or-error result is
|
|
68
|
+
* carried through here rather than unwrapped twice. The narrowing is an assertion because
|
|
69
|
+
* `formatUuid` is version-agnostic: the v7-ness is established by the caller having produced the
|
|
70
|
+
* bytes, not by anything the formatter can check.
|
|
71
|
+
*/
|
|
72
|
+
const formatUuidV7 = (result: UuidSlugError | Uint8Array): UuidSlugError | UuidV7String =>
|
|
73
|
+
result instanceof Error ? result : (formatUuid(result) as UuidSlugError | UuidV7String);
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Seeds the sequence from the same six random bytes and the same bit positions as before, split
|
|
77
|
+
* across the two halves: byte 0 and the top 2 bits of byte 1 form the high half, the rest the
|
|
78
|
+
* low half. Starting each millisecond at a random point rather than zero is what stops the
|
|
79
|
+
* sequence leaking how many ids were issued in the previous millisecond.
|
|
80
|
+
*/
|
|
81
|
+
const seedHi = (bytes: Uint8Array) => (((bytes[0] ?? 0) << 2) | ((bytes[1] ?? 0) >>> 6)) & 0x3ff;
|
|
82
|
+
|
|
83
|
+
const seedLo = (bytes: Uint8Array) =>
|
|
84
|
+
((((bytes[1] ?? 0) & 0x3f) << 26) |
|
|
85
|
+
((bytes[2] ?? 0) << 18) |
|
|
86
|
+
((bytes[3] ?? 0) << 10) |
|
|
87
|
+
((bytes[4] ?? 0) << 2) |
|
|
88
|
+
((bytes[5] ?? 0) & 0x03)) >>>
|
|
89
|
+
0;
|
|
38
90
|
|
|
39
91
|
export function createUuidV7Generator(options: UuidV7GeneratorOptions): UuidV7Generator {
|
|
40
92
|
const clock = options.clock ?? Date.now;
|
|
93
|
+
const fill = options.fillRandom;
|
|
41
94
|
const random = new Uint8Array(16);
|
|
95
|
+
/**
|
|
96
|
+
* Below every timestamp the clock check admits, which is what makes it the uninitialised
|
|
97
|
+
* sentinel rather than a value: `now > lastMs` alone therefore takes the reseed branch on the
|
|
98
|
+
* first call, and no separate "have we started" flag is needed. The coupling is deliberate and
|
|
99
|
+
* is why the clock is validated before this is compared against — an unvalidated clock returning
|
|
100
|
+
* a negative millisecond would make `lastMs` stay below it forever, so the monotonic counter
|
|
101
|
+
* would never be used and every call would reseed.
|
|
102
|
+
*/
|
|
42
103
|
let lastMs = -1;
|
|
43
|
-
let
|
|
104
|
+
let counterHi = 0;
|
|
105
|
+
let counterLo = 0;
|
|
44
106
|
|
|
45
107
|
function reseed(ms: number) {
|
|
46
|
-
|
|
108
|
+
const failed = fillRandomBytes(fill, random);
|
|
109
|
+
if (failed) return failed;
|
|
47
110
|
lastMs = ms;
|
|
48
|
-
|
|
111
|
+
counterHi = seedHi(random);
|
|
112
|
+
counterLo = seedLo(random);
|
|
113
|
+
return undefined;
|
|
49
114
|
}
|
|
50
115
|
|
|
51
|
-
function bytes(
|
|
116
|
+
function bytes(
|
|
117
|
+
out?: Uint8Array,
|
|
118
|
+
offset = 0,
|
|
119
|
+
timestamp?: number,
|
|
120
|
+
explicit = false,
|
|
121
|
+
): UuidSlugError | Uint8Array {
|
|
52
122
|
const target = out ?? new Uint8Array(16);
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
123
|
+
const badRange = checkRange(target.length, offset, 16);
|
|
124
|
+
if (badRange) return badRange;
|
|
125
|
+
// The two modes differ only in where the millisecond and the 42-bit sequence come from, so
|
|
126
|
+
// they share one write path. A caller-supplied instant takes a RANDOM sequence rather than
|
|
127
|
+
// the monotonic counter, and leaves `lastMs`/`counter` untouched: that counter orders values
|
|
128
|
+
// issued inside the CURRENT millisecond, and a caller naming an arbitrary instant is not
|
|
129
|
+
// extending that sequence. Feeding a supplied timestamp through it would be worse than
|
|
130
|
+
// useless — an older instant fails the `now > lastMs` test and the value would carry the
|
|
131
|
+
// clock's millisecond instead of the requested one.
|
|
132
|
+
let ms: number;
|
|
133
|
+
let sequenceHi: number;
|
|
134
|
+
let sequenceLo: number;
|
|
135
|
+
if (explicit) {
|
|
136
|
+
const invalid = rejectInstant(timestamp as number);
|
|
137
|
+
if (invalid) return invalid;
|
|
138
|
+
const failed = fillRandomBytes(fill, random);
|
|
139
|
+
if (failed) return failed;
|
|
140
|
+
ms = timestamp as number;
|
|
141
|
+
sequenceHi = seedHi(random);
|
|
142
|
+
sequenceLo = seedLo(random);
|
|
143
|
+
} else {
|
|
144
|
+
// Truncated THEN validated, in that order and not the other. A clock is allowed to be
|
|
145
|
+
// fractional — `performance.timeOrigin + performance.now()` is, and is a perfectly good one —
|
|
146
|
+
// so rejecting non-integers here would refuse a legitimate caller, unlike `rejectInstant`,
|
|
147
|
+
// where the fraction is in an argument the caller wrote out. What must not survive is a
|
|
148
|
+
// truncated value the format cannot carry: `writeTimestamp` keeps the low 48 bits of whatever
|
|
149
|
+
// it is handed, so NaN and 2**48 both silently produced the 1970 prefix and a negative
|
|
150
|
+
// millisecond produced the year 10889 by two's-complement wrap. All three now report.
|
|
151
|
+
// The raw reading is kept for the message rather than calling `clock()` again: a second call
|
|
152
|
+
// is a second reading, and the message would name a value other than the one refused.
|
|
153
|
+
const reading = readClock(clock);
|
|
154
|
+
if (reading instanceof Error) return reading;
|
|
155
|
+
const now = Math.trunc(reading);
|
|
156
|
+
if (reading < 0 || !isValidUuidV7Timestamp(now))
|
|
157
|
+
return new UuidSlugError(
|
|
158
|
+
"invalid_timestamp",
|
|
159
|
+
`Clock returned ${String(reading)}, which is not a millisecond in 0..${MAX_TIMESTAMP}.`,
|
|
160
|
+
);
|
|
161
|
+
if (now > lastMs) {
|
|
162
|
+
const failed = reseed(now);
|
|
163
|
+
if (failed) return failed;
|
|
164
|
+
} else {
|
|
165
|
+
counterLo = (counterLo + 1) >>> 0;
|
|
166
|
+
if (counterLo === 0) counterHi += 1;
|
|
167
|
+
// Past 42 bits the sequence no longer fits `rand_a` plus the borrowed `rand_b` bits.
|
|
168
|
+
// Borrowing the next millisecond keeps ids ordered and unique rather than wrapping into
|
|
169
|
+
// values this millisecond has already issued.
|
|
170
|
+
if (counterHi > 0x3ff) {
|
|
171
|
+
// At the ceiling there is no next millisecond to borrow: `writeTimestamp` truncates to
|
|
172
|
+
// six bytes, so `lastMs + 1` wraps to 0 and the generator restarts in 1970 — ordering
|
|
173
|
+
// broken permanently, and silently, from that call onward. Unreachable on a real clock
|
|
174
|
+
// until the year 10889; reachable now from any clock that lands near the ceiling, which
|
|
175
|
+
// is why refusing is not theoretical.
|
|
176
|
+
if (lastMs >= MAX_TIMESTAMP)
|
|
177
|
+
return new UuidSlugError(
|
|
178
|
+
"invalid_timestamp",
|
|
179
|
+
`Sequence exhausted at the last representable millisecond (${MAX_TIMESTAMP}).`,
|
|
180
|
+
);
|
|
181
|
+
const failed = reseed(lastMs + 1);
|
|
182
|
+
if (failed) return failed;
|
|
183
|
+
} else {
|
|
184
|
+
const failed = fillRandomBytes(fill, random);
|
|
185
|
+
if (failed) return failed;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
ms = lastMs;
|
|
189
|
+
sequenceHi = counterHi;
|
|
190
|
+
sequenceLo = counterLo;
|
|
61
191
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
target
|
|
66
|
-
target[offset +
|
|
67
|
-
target[offset + 14] = random[14] ?? 0;
|
|
68
|
-
target[offset + 15] = random[15] ?? 0;
|
|
192
|
+
// The checked offset applies to every store. Write directly into the target so callers
|
|
193
|
+
// reusing an output buffer also avoid allocating a temporary typed-array view.
|
|
194
|
+
writeTimestamp(target, ms, offset);
|
|
195
|
+
writeCounter(target, sequenceHi, sequenceLo, offset);
|
|
196
|
+
for (let i = 12; i < 16; i += 1) target[offset + i] = random[i] as number;
|
|
69
197
|
return target;
|
|
70
198
|
}
|
|
71
199
|
|
|
72
200
|
return {
|
|
73
201
|
uuidV7() {
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
202
|
+
const formatted = formatUuidV7(bytes());
|
|
203
|
+
// Throws rather than returns, because this signature promises a string: the two ways it can
|
|
204
|
+
// fail — entropy, and a `clock` that returns something the format cannot carry — are both
|
|
205
|
+
// configuration the caller cannot act on per call. `uuidV7At` returns its Error instead,
|
|
206
|
+
// because there the failure is a value the caller passed in at the call site.
|
|
77
207
|
if (formatted instanceof Error) throw formatted;
|
|
78
|
-
return formatted
|
|
208
|
+
return formatted;
|
|
79
209
|
},
|
|
80
|
-
|
|
210
|
+
uuidV7At: (timestamp) => formatUuidV7(bytes(undefined, 0, timestamp, true)),
|
|
211
|
+
uuidV7Bytes: (out, offset) => bytes(out, offset),
|
|
212
|
+
uuidV7BytesAt: (timestamp, out, offset) => bytes(out, offset, timestamp, true),
|
|
81
213
|
};
|
|
82
214
|
}
|
|
83
215
|
|
|
@@ -87,13 +219,23 @@ export function createRuntimeGenerator(runtime: Runtime): UuidV7Generator {
|
|
|
87
219
|
uuidV7() {
|
|
88
220
|
if (!runtime.uuidV7) return fallback.uuidV7();
|
|
89
221
|
try {
|
|
90
|
-
return runtime.uuidV7()
|
|
222
|
+
return runtime.uuidV7();
|
|
91
223
|
} catch {
|
|
92
224
|
return fallback.uuidV7();
|
|
93
225
|
}
|
|
94
226
|
},
|
|
227
|
+
// The range is checked BEFORE delegating for the same reason the instant is: a native writer
|
|
228
|
+
// is handed the caller's buffer and offset directly, and answers differently from the portable
|
|
229
|
+
// path. Measured on Bun 1.3.14, `out.set(bytes, offset)` coerces a NaN offset to 0 and writes
|
|
230
|
+
// at the wrong place reporting success, while a fractional one throws a RangeError that the
|
|
231
|
+
// catch below would relabel `rng_unavailable` — blaming the entropy source for a caller's
|
|
232
|
+
// argument. Checking here is what makes every runtime give the one answer.
|
|
95
233
|
uuidV7Bytes(out?: Uint8Array, offset = 0) {
|
|
234
|
+
// Guarded only on the branch that leaves this package: the fallback checks the same range
|
|
235
|
+
// itself, so checking before the branch would pay for it twice on every Node call.
|
|
96
236
|
if (!runtime.uuidV7Bytes) return fallback.uuidV7Bytes(out, offset);
|
|
237
|
+
const badRange = checkRange(out?.length ?? 16, offset, 16);
|
|
238
|
+
if (badRange) return badRange;
|
|
97
239
|
try {
|
|
98
240
|
return runtime.uuidV7Bytes(out, offset);
|
|
99
241
|
} catch (cause) {
|
|
@@ -102,5 +244,35 @@ export function createRuntimeGenerator(runtime: Runtime): UuidV7Generator {
|
|
|
102
244
|
});
|
|
103
245
|
}
|
|
104
246
|
},
|
|
247
|
+
// Both timestamped paths reject the instant BEFORE reaching the platform, because a native
|
|
248
|
+
// generator that accepts it may answer wrongly instead of failing: measured 2026-08-12,
|
|
249
|
+
// `Bun.randomUUIDv7("hex", NaN)` and the same call at 2^48 both return the 1970 prefix
|
|
250
|
+
// `000000000000` silently, while -1 and 1.5 throw. Each then mirrors its untimestamped
|
|
251
|
+
// sibling on a platform failure — fall back for the string form, report for the byte form —
|
|
252
|
+
// so the four entry points behave predictably in pairs.
|
|
253
|
+
uuidV7At(timestamp: number) {
|
|
254
|
+
if (!runtime.uuidV7At) return fallback.uuidV7At(timestamp);
|
|
255
|
+
const invalid = rejectInstant(timestamp);
|
|
256
|
+
if (invalid) return invalid;
|
|
257
|
+
try {
|
|
258
|
+
return runtime.uuidV7At(timestamp);
|
|
259
|
+
} catch {
|
|
260
|
+
return fallback.uuidV7At(timestamp);
|
|
261
|
+
}
|
|
262
|
+
},
|
|
263
|
+
uuidV7BytesAt(timestamp: number, out?: Uint8Array, offset = 0) {
|
|
264
|
+
if (!runtime.uuidV7BytesAt) return fallback.uuidV7BytesAt(timestamp, out, offset);
|
|
265
|
+
const invalid = rejectInstant(timestamp);
|
|
266
|
+
if (invalid) return invalid;
|
|
267
|
+
const badRange = checkRange(out?.length ?? 16, offset, 16);
|
|
268
|
+
if (badRange) return badRange;
|
|
269
|
+
try {
|
|
270
|
+
return runtime.uuidV7BytesAt(timestamp, out, offset);
|
|
271
|
+
} catch (cause) {
|
|
272
|
+
return new UuidSlugError("rng_unavailable", "Runtime UUIDv7 byte generation failed.", {
|
|
273
|
+
cause,
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
},
|
|
105
277
|
};
|
|
106
278
|
}
|
package/src/yield.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
|
|
3
|
+
const host = globalThis as {
|
|
4
|
+
setImmediate?: (callback: () => void) => unknown;
|
|
5
|
+
};
|
|
6
|
+
const immediate = host.setImmediate?.bind(host);
|
|
7
|
+
|
|
8
|
+
/** Yield to a host task so timers, input and cancellation can run; a microtask would starve them. */
|
|
9
|
+
export function yieldToHost(): Promise<void> {
|
|
10
|
+
// Prioritized scheduler continuations can overtake queued cancellation tasks in browsers.
|
|
11
|
+
if (immediate) return new Promise((resolve) => immediate(resolve));
|
|
12
|
+
return new Promise((resolve) => {
|
|
13
|
+
const channel = new MessageChannel();
|
|
14
|
+
// eslint-disable-next-line unicorn/prefer-add-event-listener -- this private port has one handler; assignment also starts delivery
|
|
15
|
+
channel.port1.onmessage = () => {
|
|
16
|
+
channel.port1.close();
|
|
17
|
+
channel.port2.close();
|
|
18
|
+
resolve();
|
|
19
|
+
};
|
|
20
|
+
channel.port2.postMessage(null);
|
|
21
|
+
});
|
|
22
|
+
}
|
package/dist/index.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/types.ts","../src/base64url.ts","../src/uuid.ts","../src/codec.ts","../src/errors.ts","../src/schema.ts","../src/runtime/types.ts","../src/v7.ts","../src/index.ts"],"mappings":";cAAc;KAEF,MAAM,GAAG,uBAAuB;YAAgB,SAAS;;KAEzD,kBAAkB;KAClB,aAAa;KACb,eAAe,MAAM;KACrB,eAAe,MAAM;KACrB,WAAW,MAAM;KACjB,aAAa,MAAM;KACnB,aAAa,MAAM;KACnB,iBAAiB,MAAM;KACvB,mBAAmB,MAAM;KACzB,qBAAqB,MAAM;KAC3B,mBAAmB,mBAAmB;KACtC,YAAY,MAAM;UAEb;EACf;EACA;;UAGe;EACf,UAAU;EACV,YAAY,MAAM,YAAY,kBAAkB,QAAQ;;UAGzC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Aa,QAAQ;iBAIvD,cAAc,cAAc,MAAM,YAAY,kBAAa,QAAQ;iBAInE,WAAW,kCAAkC,QAAQ;iBAKrD,aAAa,kCAAkC,QAAQ;iBAMvD,aAAa,kCAAkC,QAAQ;iBAMvD,uBAAuB,OAAO,YAAY;iBAM1C,iBAAiB,OAAO,YAAY;;;cCnGvC,uCAAuC;iBAiEpC,oBAAoB,UAAS,uBAA4B;cAoE5D,cAAY;iBAET,oBACd,cACA,UAAS,yBACR,QAAQ;iBAeK,wBACd,cACA,UAAU,yBACT,QAAQ;iBAOK,8BACd,cACA,UAAU,yBACT,QAAQ;;;KClNC;cAUC,sBAAsB;WACxB,MAAM;EAEf,YAAY,MAAM,mBAAmB,iBAAiB,UAAU;;cAOrD,yBAAyB;EACpC,YAAY,iBAAiB,UAAU;;;;cCwE5B,uBAAuB;iBAOpB,iBAAiB,QAAQ,qBAAqB,QAAQ;iBAItD,iBAAiB,SAAS,oBAAoB,QAAQ;cAezD,qBAAqB;;;UCvHjB;;;;;;EAMf,WAAW,OAAO,WAAW;EAC7B;EACA;EACA,aAAa,MAAM,YAAY,kBAAkB;EACjD;;;;UCLe;WACN;WACA,aAAa,OAAO,WAAW;;iBA+B1B,sBAAsB,SAAS,yBAAyB;iBA6CxD,uBAAuB,SAAS,UAAU;;;cCrB7C,cAAA;cACA,cAAA;cACA,cAAW,MAAA,YAAA,oBAAA,QAAA;cACX,cAAW,MAAA,YAAA,oBAAA,QAAA;cACX,kBAAA;cACA,kBAAA;cACA,wBAAA;cACA,mBAAgB,iBAAA,QAAA;cAChB,mBAAgB,iBAAA,QAAA;cAChB,qBAAkB,iBAAA,QAAA;cAClB,qBAAkB,iBAAA,QAAA;cAClB,4BAAA"}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/errors.ts","../src/base64url.ts","../src/runtime/node.ts","../src/uuid.ts","../src/mask.ts","../src/schema.ts","../src/v7.ts","../src/codec.ts","../src/index.ts"],"sourcesContent":["export type UuidSlugErrorCode =\n | \"invalid_base64url\"\n | \"invalid_buffer\"\n | \"invalid_mask_schema\"\n | \"invalid_uuid\"\n | \"invalid_uuid_slug\"\n | \"invalid_uuid_version\"\n | \"rng_unavailable\"\n | \"stale_uuid\";\n\nexport class UuidSlugError extends Error {\n readonly code: UuidSlugErrorCode;\n\n constructor(code: UuidSlugErrorCode, message: string, options?: ErrorOptions) {\n super(message, options);\n this.name = \"UuidSlugError\";\n this.code = code;\n }\n}\n\nexport class UuidRuntimeError extends UuidSlugError {\n constructor(message: string, options?: ErrorOptions) {\n super(\"rng_unavailable\", message, options);\n this.name = \"UuidRuntimeError\";\n }\n}\n","import { UuidSlugError } from \"./errors\";\nimport type { Base64UrlString } from \"./types\";\n\nconst ALPHABET = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_\";\nconst DECODE = new Int16Array(128).fill(-1);\nfor (let i = 0; i < ALPHABET.length; i += 1) DECODE[ALPHABET.charCodeAt(i)] = i;\n\nfunction byteAt(bytes: Uint8Array, index: number) {\n return bytes[index] ?? 0;\n}\n\nexport function encodeBase64Url(bytes: Uint8Array): Base64UrlString {\n let out = \"\";\n let i = 0;\n for (; i + 2 < bytes.length; i += 3) {\n const value = (byteAt(bytes, i) << 16) | (byteAt(bytes, i + 1) << 8) | byteAt(bytes, i + 2);\n out += ALPHABET[(value >>> 18) & 63];\n out += ALPHABET[(value >>> 12) & 63];\n out += ALPHABET[(value >>> 6) & 63];\n out += ALPHABET[value & 63];\n }\n const remaining = bytes.length - i;\n if (remaining === 1) {\n const value = byteAt(bytes, i) << 16;\n out += ALPHABET[(value >>> 18) & 63];\n out += ALPHABET[(value >>> 12) & 63];\n }\n if (remaining === 2) {\n const value = (byteAt(bytes, i) << 16) | (byteAt(bytes, i + 1) << 8);\n out += ALPHABET[(value >>> 18) & 63];\n out += ALPHABET[(value >>> 12) & 63];\n out += ALPHABET[(value >>> 6) & 63];\n }\n return out as Base64UrlString;\n}\n\nexport function decodeBase64Url(value: string, out?: Uint8Array, offset = 0): Error | Uint8Array {\n if (value.includes(\"=\"))\n return new UuidSlugError(\"invalid_base64url\", \"Base64url value must be unpadded.\");\n if (value.length % 4 === 1)\n return new UuidSlugError(\"invalid_base64url\", \"Base64url length is impossible.\");\n\n const byteLength = Math.floor((value.length * 6) / 8);\n const target = out ?? new Uint8Array(byteLength);\n if (offset < 0 || offset + byteLength > target.length)\n return new UuidSlugError(\"invalid_buffer\", \"Output buffer is too small.\");\n\n let buffer = 0;\n let bits = 0;\n let written = 0;\n for (let i = 0; i < value.length; i += 1) {\n const code = value.charCodeAt(i);\n const decoded = code < DECODE.length ? (DECODE[code] ?? -1) : -1;\n if (decoded < 0)\n return new UuidSlugError(\"invalid_base64url\", `Invalid base64url character at offset ${i}.`);\n buffer = (buffer << 6) | decoded;\n bits += 6;\n if (bits >= 8) {\n bits -= 8;\n target[offset + written] = (buffer >>> bits) & 0xff;\n written += 1;\n }\n }\n if (bits > 0 && (buffer & ((1 << bits) - 1)) !== 0) {\n return new UuidSlugError(\n \"invalid_base64url\",\n \"Base64url value has non-canonical trailing bits.\",\n );\n }\n return out ? target : target.subarray(0, byteLength);\n}\n\nexport function isBase64Url(value: null | string | undefined): value is Base64UrlString {\n if (!value || value.includes(\"=\") || value.length % 4 === 1) return false;\n return decodeBase64Url(value) instanceof Error ? false : true;\n}\n","import crypto from \"node:crypto\";\nimport { UuidRuntimeError } from \"../errors\";\nimport type { Runtime } from \"./types\";\n\ntype NodeCryptoWithV7 = {\n randomUUIDv7?: () => string;\n};\n\nconst cryptoWithV7 = crypto as typeof crypto & NodeCryptoWithV7;\n\nexport const runtime: Runtime = {\n fillRandom(bytes) {\n bytes.set(crypto.randomBytes(bytes.length));\n },\n uuidV4() {\n return crypto.randomUUID();\n },\n uuidV7() {\n if (!cryptoWithV7.randomUUIDv7)\n throw new UuidRuntimeError(\"Node crypto.randomUUIDv7 is unavailable.\");\n return cryptoWithV7.randomUUIDv7();\n },\n};\n","import { decodeBase64Url, encodeBase64Url } from \"./base64url\";\nimport { UuidSlugError } from \"./errors\";\nimport type {\n UuidSlug,\n UuidString,\n UuidV4Slug,\n UuidV4String,\n UuidV7Slug,\n UuidV7String,\n} from \"./types\";\n\nconst HEX = \"0123456789abcdef\";\nconst HEX_DECODE = new Int8Array(128).fill(-1);\nfor (let i = 0; i < 10; i += 1) HEX_DECODE[48 + i] = i;\nfor (let i = 0; i < 6; i += 1) HEX_DECODE[97 + i] = 10 + i;\n\nconst UUID_LENGTH = 36;\nconst SLUG_LENGTH = 22;\nconst UUID_BYTE_OFFSETS = [0, 2, 4, 6, 9, 11, 14, 16, 19, 21, 24, 26, 28, 30, 32, 34] as const;\n\nfunction hexValue(code: number) {\n return code < HEX_DECODE.length ? HEX_DECODE[code] : -1;\n}\n\nexport function parseUuid(uuid: string, out?: Uint8Array, offset = 0): Error | Uint8Array {\n if (uuid.length !== UUID_LENGTH)\n return new UuidSlugError(\"invalid_uuid\", \"UUID must be 36 characters.\");\n if (uuid[8] !== \"-\" || uuid[13] !== \"-\" || uuid[18] !== \"-\" || uuid[23] !== \"-\") {\n return new UuidSlugError(\"invalid_uuid\", \"UUID hyphen positions are invalid.\");\n }\n\n const target = out ?? new Uint8Array(16);\n if (offset < 0 || offset + 16 > target.length)\n return new UuidSlugError(\"invalid_buffer\", \"Output buffer is too small.\");\n\n for (let byteIndex = 0; byteIndex < UUID_BYTE_OFFSETS.length; byteIndex += 1) {\n const textOffset = UUID_BYTE_OFFSETS[byteIndex] ?? 0;\n const high = hexValue(uuid.charCodeAt(textOffset)) ?? -1;\n const low = hexValue(uuid.charCodeAt(textOffset + 1)) ?? -1;\n if (high < 0 || low < 0)\n return new UuidSlugError(\"invalid_uuid\", `Invalid UUID hex at offset ${textOffset}.`);\n target[offset + byteIndex] = (high << 4) | low;\n }\n return target;\n}\n\nexport function formatUuid(bytes: Uint8Array, offset = 0): Error | UuidString {\n if (offset < 0 || offset + 16 > bytes.length)\n return new UuidSlugError(\"invalid_buffer\", \"UUID byte buffer is too small.\");\n let out = \"\";\n for (let i = 0; i < 16; i += 1) {\n if (i === 4 || i === 6 || i === 8 || i === 10) out += \"-\";\n const byte = bytes[offset + i] ?? 0;\n out += HEX[byte >>> 4];\n out += HEX[byte & 0x0f];\n }\n return out as UuidString;\n}\n\nexport function uuidVersion(bytes: Uint8Array, offset = 0): number {\n return (bytes[offset + 6] ?? 0) >>> 4;\n}\n\nexport function isRfcVariant(bytes: Uint8Array, offset = 0): boolean {\n return (bytes[offset + 8] ?? 0) >>> 6 === 0b10;\n}\n\nexport function isUuidString(uuid: null | string | undefined): uuid is UuidString {\n if (!uuid) return false;\n return parseUuid(uuid) instanceof Error ? false : true;\n}\n\nexport function isUuidV4String(uuid: null | string | undefined): uuid is UuidV4String {\n if (!uuid) return false;\n const bytes = parseUuid(uuid);\n return bytes instanceof Error ? false : uuidVersion(bytes) === 4 && isRfcVariant(bytes);\n}\n\nexport function isUuidV7String(uuid: null | string | undefined): uuid is UuidV7String {\n if (!uuid) return false;\n const bytes = parseUuid(uuid);\n return bytes instanceof Error ? false : uuidVersion(bytes) === 7 && isRfcVariant(bytes);\n}\n\nexport function isUuidV7Bytes(bytes: Uint8Array): boolean {\n return bytes.length === 16 && uuidVersion(bytes) === 7 && isRfcVariant(bytes);\n}\n\nexport function uuidBytesToSlug(bytes: Uint8Array, offset = 0): Error | UuidSlug {\n if (offset < 0 || offset + 16 > bytes.length)\n return new UuidSlugError(\"invalid_buffer\", \"UUID byte buffer is too small.\");\n return encodeBase64Url(bytes.subarray(offset, offset + 16)) as UuidSlug;\n}\n\nexport function slugToUuidBytes(slug: string, out?: Uint8Array, offset = 0): Error | Uint8Array {\n if (slug.length !== SLUG_LENGTH)\n return new UuidSlugError(\"invalid_uuid_slug\", \"UUID slug must be 22 characters.\");\n return decodeBase64Url(slug, out, offset);\n}\n\nexport function uuidToSlug(uuid: string): Error | UuidSlug {\n const bytes = parseUuid(uuid);\n if (bytes instanceof Error) return bytes;\n return uuidBytesToSlug(bytes);\n}\n\nexport function slugToUuid(slug: string): Error | UuidString {\n const bytes = slugToUuidBytes(slug);\n if (bytes instanceof Error) return bytes;\n return formatUuid(bytes);\n}\n\nexport function formatUuidSlug(bytes: Uint8Array, offset = 0): Error | UuidSlug {\n return uuidBytesToSlug(bytes, offset);\n}\n\nexport function parseUuidSlug(slug: string, out?: Uint8Array, offset = 0): Error | Uint8Array {\n return slugToUuidBytes(slug, out, offset);\n}\n\nexport function isUuidSlug(slug: null | string | undefined): slug is UuidSlug {\n if (!slug || slug.length !== SLUG_LENGTH) return false;\n return slugToUuidBytes(slug) instanceof Error ? false : true;\n}\n\nexport function isUuidV4Slug(slug: null | string | undefined): slug is UuidV4Slug {\n if (!slug) return false;\n const bytes = slugToUuidBytes(slug);\n return bytes instanceof Error ? false : uuidVersion(bytes) === 4 && isRfcVariant(bytes);\n}\n\nexport function isUuidV7Slug(slug: null | string | undefined): slug is UuidV7Slug {\n if (!slug) return false;\n const bytes = slugToUuidBytes(slug);\n return bytes instanceof Error ? false : uuidVersion(bytes) === 7 && isRfcVariant(bytes);\n}\n\nexport function extractUuidV7Timestamp(bytes: Uint8Array, offset = 0): number {\n let timestamp = 0;\n for (let i = 0; i < 6; i += 1) timestamp = timestamp * 256 + (bytes[offset + i] ?? 0);\n return timestamp;\n}\n\nexport function hasUuidV7Entropy(bytes: Uint8Array, offset = 0): boolean {\n const randA = (((bytes[offset + 6] ?? 0) & 0x0f) << 8) | (bytes[offset + 7] ?? 0);\n const randBFirst = (bytes[offset + 8] ?? 0) & 0x3f;\n let restZero = true;\n let restMax = true;\n for (let i = 9; i < 16; i += 1) {\n const byte = bytes[offset + i] ?? 0;\n if (byte !== 0x00) restZero = false;\n if (byte !== 0xff) restMax = false;\n }\n return (\n !(randA === 0 && randBFirst === 0 && restZero) &&\n !(randA === 0x0fff && randBFirst === 0x3f && restMax)\n );\n}\n","import { UuidSlugError } from \"./errors\";\nimport {\n formatUuid,\n isRfcVariant,\n parseUuid,\n slugToUuidBytes,\n uuidBytesToSlug,\n uuidVersion,\n} from \"./uuid\";\nimport type {\n MaskSchema,\n MaskedUuidSlug,\n MaskedUuidV7Slug,\n UuidString,\n UuidV7String,\n} from \"./types\";\n\nfunction checksum4(bytes: Uint8Array): number {\n let acc = 0;\n for (const byte of bytes) acc ^= byte;\n return (acc >>> 4) ^ (acc & 0x0f);\n}\n\nfunction checksum6(bytes: Uint8Array): number {\n let acc = 0;\n for (let i = 0; i < bytes.length; i += 1) acc = (acc + (bytes[i] ?? 0) * (i + 17)) & 0xff;\n return ((acc >>> 2) ^ acc) & 0x3f;\n}\n\nfunction tagFor(bytes: Uint8Array, tagBits: 4 | 6) {\n return tagBits === 4 ? checksum4(bytes) : checksum6(bytes);\n}\n\nfunction injectTag(bytes: Uint8Array, tag: number, tagBits: 4 | 6) {\n bytes[6] = ((tag & 0x0f) << 4) | ((bytes[6] ?? 0) & 0x0f);\n if (tagBits === 6) bytes[8] = ((tag & 0x30) << 2) | ((bytes[8] ?? 0) & 0x3f);\n}\n\nfunction extractTag(bytes: Uint8Array, tagBits: 4 | 6) {\n const versionBits = (bytes[6] ?? 0) >>> 4;\n if (tagBits === 4) return versionBits;\n return versionBits | (((bytes[8] ?? 0) >>> 6) << 4);\n}\n\nfunction restoreV7(bytes: Uint8Array, tagBits: 4 | 6) {\n bytes[6] = ((bytes[6] ?? 0) & 0x0f) | 0x70;\n if (tagBits === 6) bytes[8] = ((bytes[8] ?? 0) & 0x3f) | 0x80;\n}\n\nexport function uuidToMaskedSlugWithSchema(\n uuid: string,\n schema: MaskSchema,\n): Error | MaskedUuidSlug {\n const raw = parseUuid(uuid);\n if (raw instanceof Error) return raw;\n if (uuidVersion(raw) !== 7 || !isRfcVariant(raw))\n return new UuidSlugError(\"invalid_uuid_version\", \"Masked UUID slugs currently require UUIDv7.\");\n return uuidV7BytesToMaskedSlug(raw, schema);\n}\n\nexport function uuidV7BytesToMaskedSlug(\n raw: Uint8Array,\n schema: MaskSchema,\n): Error | MaskedUuidV7Slug {\n const tagged = new Uint8Array(raw);\n injectTag(tagged, tagFor(raw, schema.tagBits), schema.tagBits);\n const mixed = new Uint8Array(16);\n for (let i = 0; i < 16; i += 1)\n mixed[i] = (tagged[schema.permute[i] ?? 0] ?? 0) ^ (schema.xor[i] ?? 0);\n const slug = uuidBytesToSlug(mixed);\n return slug instanceof Error ? slug : (slug as MaskedUuidV7Slug);\n}\n\nexport function maskedSlugToUuidWithSchema(slug: string, schema: MaskSchema): Error | UuidString {\n const mixed = slugToUuidBytes(slug);\n if (mixed instanceof Error) return mixed;\n const unmixed = new Uint8Array(16);\n for (let i = 0; i < 16; i += 1) {\n const source = schema.inverse[i] ?? 0;\n unmixed[i] = (mixed[source] ?? 0) ^ (schema.xor[source] ?? 0);\n }\n const foundTag = extractTag(unmixed, schema.tagBits);\n restoreV7(unmixed, schema.tagBits);\n if (tagFor(unmixed, schema.tagBits) !== foundTag)\n return new UuidSlugError(\"invalid_uuid_slug\", \"Masked UUID slug failed schema validation.\");\n return formatUuid(unmixed);\n}\n\nexport function maskedSlugToUuidV7WithSchema(\n slug: string,\n schema: MaskSchema,\n): Error | UuidV7String {\n const uuid = maskedSlugToUuidWithSchema(slug, schema);\n return uuid instanceof Error ? uuid : (uuid as UuidV7String);\n}\n","import { UuidSlugError } from \"./errors\";\nimport type { ExplicitMaskSchema, MaskSchema, MaskSchemaOptions } from \"./types\";\n\nconst LEGACY_PERMUTE = Uint8Array.from([9, 13, 3, 8, 14, 0, 11, 7, 6, 1, 15, 4, 2, 5, 10, 12]);\nconst LEGACY_XOR = Uint8Array.from([\n 0xa2, 0x70, 0x32, 0x7f, 0x98, 0xb8, 0x9b, 0x5e, 0x1b, 0x26, 0xb6, 0x16, 0x96, 0xf9, 0xea, 0x3e,\n]);\n\nfunction clone16(bytes: Uint8Array, name: string): Error | Uint8Array {\n if (bytes.length !== 16)\n return new UuidSlugError(\"invalid_mask_schema\", `${name} must contain exactly 16 bytes.`);\n return new Uint8Array(bytes);\n}\n\nfunction inversePermutation(permute: Uint8Array): Error | Uint8Array {\n if (permute.length !== 16)\n return new UuidSlugError(\"invalid_mask_schema\", \"Permutation must contain exactly 16 bytes.\");\n const seen = new Uint8Array(16);\n const inverse = new Uint8Array(16);\n for (let i = 0; i < 16; i += 1) {\n const value = permute[i] ?? 255;\n if (value > 15 || seen[value] === 1)\n return new UuidSlugError(\n \"invalid_mask_schema\",\n \"Permutation must be a bijection over 0..15.\",\n );\n seen[value] = 1;\n inverse[value] = i;\n }\n return inverse;\n}\n\nfunction fnv1a64(data: Uint8Array) {\n let hash = 0xcbf29ce484222325n;\n for (const byte of data) {\n hash ^= BigInt(byte);\n hash = BigInt.asUintN(64, hash * 0x100000001b3n);\n }\n return hash;\n}\n\nfunction seedBytes(seed: string | Uint8Array) {\n if (typeof seed !== \"string\") return new Uint8Array(seed);\n return new TextEncoder().encode(seed);\n}\n\nfunction next64(state: { value: bigint }) {\n state.value ^= state.value << 13n;\n state.value ^= state.value >> 7n;\n state.value ^= state.value << 17n;\n state.value = BigInt.asUintN(64, state.value);\n return state.value;\n}\n\nfunction derivedBytes(seed: Uint8Array, purpose: number, length: number) {\n const state = {\n value: fnv1a64(Uint8Array.from([...seed, purpose])) || 0x9e3779b97f4a7c15n,\n };\n const out = new Uint8Array(length);\n for (let i = 0; i < length; i += 1)\n out[i] = Number((next64(state) >> BigInt((i % 8) * 8)) & 0xffn);\n return out;\n}\n\nfunction derivedPermutation(seed: Uint8Array) {\n const random = derivedBytes(seed, 2, 64);\n const permute = Uint8Array.from({ length: 16 }, (_, i) => i);\n let cursor = 0;\n for (let i = 15; i > 0; i -= 1) {\n const j = (random[cursor] ?? 0) % (i + 1);\n cursor += 1;\n const tmp = permute[i] ?? 0;\n permute[i] = permute[j] ?? 0;\n permute[j] = tmp;\n }\n return permute;\n}\n\nfunction completeSchema(\n id: string,\n xorInput: Uint8Array,\n permuteInput: Uint8Array,\n tagBits: 4 | 6,\n): Error | MaskSchema {\n const xor = clone16(xorInput, \"XOR mask\");\n if (xor instanceof Error) return xor;\n const permute = clone16(permuteInput, \"Permutation\");\n if (permute instanceof Error) return permute;\n const inverse = inversePermutation(permute);\n if (inverse instanceof Error) return inverse;\n return { id, inverse, permute, tagBits, xor };\n}\n\nexport const LEGACY_MASK_SCHEMA_V1: MaskSchema = completeSchema(\n \"legacy-mask-v1\",\n LEGACY_XOR,\n LEGACY_PERMUTE,\n 4,\n) as MaskSchema;\n\nexport function defineMaskSchema(schema: ExplicitMaskSchema): Error | MaskSchema {\n return completeSchema(schema.id ?? \"explicit\", schema.xor, schema.permute, schema.tagBits);\n}\n\nexport function createMaskSchema(options: MaskSchemaOptions): Error | MaskSchema {\n const seed = seedBytes(options.seed);\n if (seed.length === 0)\n return new UuidSlugError(\"invalid_mask_schema\", \"Mask seed must not be empty.\");\n const tagBits = options.tagBits ?? 6;\n if (tagBits !== 4 && tagBits !== 6)\n return new UuidSlugError(\"invalid_mask_schema\", \"Mask tagBits must be 4 or 6.\");\n return completeSchema(\n options.id ?? \"seeded\",\n derivedBytes(seed, 1, 16),\n derivedPermutation(seed),\n tagBits,\n );\n}\n\nexport const DEFAULT_MASK_SCHEMA: MaskSchema = createMaskSchema({\n id: \"default\",\n seed: \"anizoptera.uuid-slug.default-mask.v1\",\n}) as MaskSchema;\n","import { 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) {\n let value = Math.trunc(ms);\n for (let i = 5; i >= 0; i -= 1) {\n bytes[i] = value & 0xff;\n value = Math.floor(value / 256);\n }\n}\n\nfunction writeCounter(bytes: Uint8Array, counter: bigint) {\n bytes[6] = 0x70 | Number((counter >> 38n) & 0x0fn);\n bytes[7] = Number((counter >> 30n) & 0xffn);\n bytes[8] = 0x80 | Number((counter >> 24n) & 0x3fn);\n bytes[9] = Number((counter >> 16n) & 0xffn);\n bytes[10] = Number((counter >> 8n) & 0xffn);\n bytes[11] = Number(counter & 0xffn);\n}\n\nfunction readCounterSeed(bytes: Uint8Array) {\n return (\n (BigInt(bytes[0] ?? 0) << 34n) |\n (BigInt(bytes[1] ?? 0) << 26n) |\n (BigInt(bytes[2] ?? 0) << 18n) |\n (BigInt(bytes[3] ?? 0) << 10n) |\n (BigInt(bytes[4] ?? 0) << 2n) |\n (BigInt(bytes[5] ?? 0) & 0x03n)\n );\n}\n\nexport function createUuidV7Generator(options: UuidV7GeneratorOptions): UuidV7Generator {\n const clock = options.clock ?? Date.now;\n const random = new Uint8Array(16);\n let lastMs = -1;\n let counter = 0n;\n\n function reseed(ms: number) {\n options.fillRandom(random);\n lastMs = ms;\n counter = readCounterSeed(random);\n }\n\n function bytes(out?: Uint8Array, offset = 0): Error | Uint8Array {\n const target = out ?? new Uint8Array(16);\n if (offset < 0 || offset + 16 > target.length)\n return new UuidSlugError(\"invalid_buffer\", \"Output buffer is too small.\");\n const now = Math.trunc(clock());\n if (lastMs < 0 || now > lastMs) reseed(now);\n else {\n counter += 1n;\n if (counter > 0x3ffffffffffn) reseed(lastMs + 1);\n else options.fillRandom(random);\n }\n const uuid = target.subarray(offset, offset + 16);\n writeTimestamp(uuid, lastMs);\n writeCounter(uuid, counter);\n target[offset + 12] = random[12] ?? 0;\n target[offset + 13] = random[13] ?? 0;\n target[offset + 14] = random[14] ?? 0;\n target[offset + 15] = random[15] ?? 0;\n return target;\n }\n\n return {\n uuidV7() {\n const result = bytes();\n if (result instanceof Error) throw result;\n const formatted = formatUuid(result);\n if (formatted instanceof Error) throw formatted;\n return formatted as UuidV7String;\n },\n uuidV7Bytes: bytes,\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() as UuidV7String;\n } catch {\n return fallback.uuidV7();\n }\n },\n uuidV7Bytes(out?: Uint8Array, offset = 0) {\n if (!runtime.uuidV7Bytes) return fallback.uuidV7Bytes(out, offset);\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 };\n}\n","import { runtime } from \"#runtime\";\nimport { UuidSlugError } from \"./errors\";\nimport {\n uuidToMaskedSlugWithSchema,\n uuidV7BytesToMaskedSlug,\n maskedSlugToUuidWithSchema,\n} from \"./mask\";\nimport { createMaskSchema, DEFAULT_MASK_SCHEMA } from \"./schema\";\nimport type {\n MaskSchema,\n MaskedUuidSlug,\n MaskedUuidV7Slug,\n PublicUuidV7Slug,\n SentinelUuidV7Slug,\n UuidSlug,\n UuidSlugCodec,\n UuidSlugCodecOptions,\n UuidString,\n UuidV4Slug,\n UuidV4String,\n UuidV7Sentinel,\n UuidV7String,\n UuidV7Slug,\n} from \"./types\";\nimport { createRuntimeGenerator } from \"./v7\";\nimport {\n formatUuid,\n formatUuidSlug,\n hasUuidV7Entropy,\n isUuidSlug,\n isUuidV4Slug,\n isUuidV4String,\n isUuidV7Slug,\n isUuidV7String,\n isUuidString,\n parseUuid,\n parseUuidSlug,\n slugToUuid,\n uuidBytesToSlug,\n uuidToSlug,\n extractUuidV7Timestamp,\n} from \"./uuid\";\nimport type { FreshValidationOptions, UuidV7SentinelDefinition } from \"./types\";\n\nexport const UUID_V7_SENTINEL_DEFINITIONS: readonly UuidV7SentinelDefinition[] = [\n {\n name: \"nil\",\n uuid: \"00000000-0000-7000-8000-000000000000\" as UuidV7String,\n },\n {\n name: \"anonymousUser\",\n uuid: \"00000000-0001-7000-8000-000000000000\" as UuidV7String,\n },\n {\n name: \"unknownUser\",\n uuid: \"00000000-0002-7000-8000-000000000000\" as UuidV7String,\n },\n];\n\nfunction schemaFromOption(mask: UuidSlugCodecOptions[\"mask\"]): Error | MaskSchema {\n if (!mask) return DEFAULT_MASK_SCHEMA;\n if (\"xor\" in mask && \"permute\" in mask && \"inverse\" in mask) return mask;\n return createMaskSchema(mask);\n}\n\nfunction createSentinels(definitions: readonly UuidV7SentinelDefinition[]) {\n const sentinels: UuidV7Sentinel[] = [];\n const byUuid = new Map<string, SentinelUuidV7Slug>();\n const bySlug = new Map<string, UuidV7String>();\n for (const definition of definitions) {\n const slug = uuidToSlug(definition.uuid);\n if (slug instanceof Error) throw slug;\n const sentinel = {\n name: definition.name,\n slug: slug as SentinelUuidV7Slug,\n uuid: definition.uuid,\n };\n sentinels.push(sentinel);\n byUuid.set(definition.uuid, sentinel.slug);\n bySlug.set(sentinel.slug, definition.uuid);\n }\n return { bySlug, byUuid, sentinels };\n}\n\n/**\n * Randomness is drawn into a private buffer and copied out instead of filled through a view\n * of the caller's array. `fillRandom` requires a plain `ArrayBuffer` because Web Crypto\n * rejects a `SharedArrayBuffer` view, and a caller-supplied `out` carries no such guarantee.\n * Reused rather than allocated per call, matching the v7 generator, so the cost is one\n * 16-byte copy.\n */\nconst v4Random = new Uint8Array(16);\n\nfunction generateUuidV4Bytes(out?: Uint8Array, offset = 0): Error | Uint8Array {\n const target = out ?? new Uint8Array(16);\n if (offset < 0 || offset + 16 > target.length)\n return new UuidSlugError(\"invalid_buffer\", \"Output buffer is too small.\");\n runtime.fillRandom(v4Random);\n target.set(v4Random, offset);\n target[offset + 6] = ((target[offset + 6] ?? 0) & 0x0f) | 0x40;\n target[offset + 8] = ((target[offset + 8] ?? 0) & 0x3f) | 0x80;\n return target;\n}\n\nfunction errorOrThrow<T>(value: Error | T): T {\n if (value instanceof Error) throw value;\n return value;\n}\n\nexport function createUuidSlugCodec(options: UuidSlugCodecOptions = {}): UuidSlugCodec {\n const schema = errorOrThrow(schemaFromOption(options.mask));\n const legacyMasks = options.legacy?.masks ?? [];\n const generator = options.generator ?? createRuntimeGenerator(runtime);\n const sentinelState = createSentinels(options.sentinels ?? UUID_V7_SENTINEL_DEFINITIONS);\n\n function decodeMasked(slug: string): Error | UuidString {\n const sentinel = sentinelState.bySlug.get(slug);\n if (sentinel) return sentinel;\n const primary = maskedSlugToUuidWithSchema(slug, schema);\n if (!(primary instanceof Error)) return primary;\n for (const legacy of legacyMasks) {\n const decoded = maskedSlugToUuidWithSchema(slug, legacy);\n if (!(decoded instanceof Error)) return decoded;\n }\n if (options.legacy?.directDecode === true) return slugToUuid(slug);\n return primary;\n }\n\n function uuidV7ToMaskedSlug(uuid: string): Error | PublicUuidV7Slug {\n const sentinel = sentinelState.byUuid.get(uuid);\n if (sentinel) return sentinel;\n return uuidToMaskedSlugWithSchema(uuid, schema) as Error | PublicUuidV7Slug;\n }\n\n return {\n sentinels: sentinelState.sentinels,\n uuidV4() {\n const native = runtime.uuidV4?.();\n if (native) return native as UuidV4String;\n return errorOrThrow(formatUuid(errorOrThrow(generateUuidV4Bytes()))) as UuidV4String;\n },\n uuidV7() {\n return generator.uuidV7();\n },\n uuidV4Bytes: generateUuidV4Bytes,\n uuidV7Bytes: generator.uuidV7Bytes,\n uuidV4Slug() {\n return errorOrThrow(uuidBytesToSlug(errorOrThrow(generateUuidV4Bytes()))) as UuidV4Slug;\n },\n uuidV7Slug() {\n if (runtime.uuidV7Slug) return runtime.uuidV7Slug() as UuidV7Slug;\n return errorOrThrow(uuidBytesToSlug(errorOrThrow(generator.uuidV7Bytes()))) as UuidV7Slug;\n },\n uuidV7MaskedSlug() {\n return errorOrThrow(uuidV7BytesToMaskedSlug(errorOrThrow(generator.uuidV7Bytes()), schema));\n },\n uuidToSlug,\n slugToUuid,\n uuidToMaskedSlug(uuid) {\n return uuidV7ToMaskedSlug(uuid) as Error | MaskedUuidSlug;\n },\n maskedSlugToUuid: decodeMasked,\n uuidV7ToMaskedSlug,\n maskedSlugToUuidV7(slug) {\n const decoded = decodeMasked(slug);\n if (decoded instanceof Error) return decoded;\n return isUuidV7String(decoded)\n ? decoded\n : new UuidSlugError(\"invalid_uuid_version\", \"Decoded UUID is not UUIDv7.\");\n },\n parseUuid,\n formatUuid,\n parseUuidSlug,\n formatUuidSlug,\n };\n}\n\nexport const defaultCodec = createUuidSlugCodec();\n\nexport function validateUuidV7Fresh(\n uuid: string,\n options: FreshValidationOptions = {},\n): Error | UuidV7String {\n if (!isUuidV7String(uuid))\n return new UuidSlugError(\"invalid_uuid\", \"Expected canonical UUIDv7 string.\");\n const bytes = parseUuid(uuid);\n if (bytes instanceof Error) return bytes;\n const windowMs = options.windowMs ?? 86_400_000;\n const now = options.now?.() ?? Date.now();\n const timestamp = extractUuidV7Timestamp(bytes);\n if (timestamp < now - windowMs || timestamp > now + windowMs)\n return new UuidSlugError(\"stale_uuid\", \"UUIDv7 timestamp is outside the accepted window.\");\n if (!hasUuidV7Entropy(bytes))\n return new UuidSlugError(\"invalid_uuid\", \"UUIDv7 random payload is degenerate.\");\n return uuid;\n}\n\nexport function validateUuidV7SlugFresh(\n slug: string,\n options?: FreshValidationOptions,\n): Error | UuidV7Slug {\n const uuid = slugToUuid(slug);\n if (uuid instanceof Error) return uuid;\n const valid = validateUuidV7Fresh(uuid, options);\n return valid instanceof Error ? valid : (slug as UuidV7Slug);\n}\n\nexport function validateMaskedUuidV7SlugFresh(\n slug: string,\n options?: FreshValidationOptions,\n): Error | MaskedUuidV7Slug {\n const uuid = defaultCodec.maskedSlugToUuidV7(slug);\n if (uuid instanceof Error) return uuid;\n const valid = validateUuidV7Fresh(uuid, options);\n return valid instanceof Error ? valid : (slug as MaskedUuidV7Slug);\n}\n\nexport { isUuidSlug, isUuidString, isUuidV4Slug, isUuidV4String, isUuidV7Slug, isUuidV7String };\n","export { decodeBase64Url, encodeBase64Url, isBase64Url } from \"./base64url\";\nexport {\n UUID_V7_SENTINEL_DEFINITIONS,\n createUuidSlugCodec,\n defaultCodec,\n validateMaskedUuidV7SlugFresh,\n validateUuidV7Fresh,\n validateUuidV7SlugFresh,\n} from \"./codec\";\nexport { UuidRuntimeError, UuidSlugError } from \"./errors\";\nexport {\n DEFAULT_MASK_SCHEMA,\n LEGACY_MASK_SCHEMA_V1,\n createMaskSchema,\n defineMaskSchema,\n} from \"./schema\";\nexport type {\n Base64UrlString,\n ExplicitMaskSchema,\n FreshValidationOptions,\n MaskSchema,\n MaskSchemaOptions,\n MaskedUuidSlug,\n MaskedUuidV7Slug,\n PublicUuidV7Slug,\n SentinelUuidV7Slug,\n UuidBytes,\n UuidSlug,\n UuidSlugCodec,\n UuidSlugCodecOptions,\n UuidString,\n UuidV4Slug,\n UuidV4String,\n UuidV7Generator,\n UuidV7Sentinel,\n UuidV7SentinelDefinition,\n UuidV7Slug,\n UuidV7String,\n} from \"./types\";\nexport {\n extractUuidV7Timestamp,\n formatUuid,\n formatUuidSlug,\n hasUuidV7Entropy,\n isUuidSlug,\n isUuidV4Slug,\n isUuidV4String,\n isUuidV7Bytes,\n isUuidV7Slug,\n isUuidV7String,\n isUuidString,\n parseUuid,\n parseUuidSlug,\n slugToUuid,\n slugToUuidBytes,\n uuidBytesToSlug,\n uuidToSlug,\n} from \"./uuid\";\nexport { createRuntimeGenerator, createUuidV7Generator } from \"./v7\";\n\nimport { defaultCodec } from \"./codec\";\n\nexport const uuidV4 = defaultCodec.uuidV4;\nexport const uuidV7 = defaultCodec.uuidV7;\nexport const uuidV4Bytes = defaultCodec.uuidV4Bytes;\nexport const uuidV7Bytes = defaultCodec.uuidV7Bytes;\nexport const uuidV4Slug = defaultCodec.uuidV4Slug;\nexport const uuidV7Slug = defaultCodec.uuidV7Slug;\nexport const uuidV7MaskedSlug = defaultCodec.uuidV7MaskedSlug;\nexport const uuidToMaskedSlug = defaultCodec.uuidToMaskedSlug;\nexport const maskedSlugToUuid = defaultCodec.maskedSlugToUuid;\nexport const uuidV7ToMaskedSlug = defaultCodec.uuidV7ToMaskedSlug;\nexport const maskedSlugToUuid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