This commit is contained in:
Dax Raad
2025-05-18 14:13:04 -04:00
parent bcd2fd68b7
commit 0e303e6508
12 changed files with 493 additions and 144 deletions

View File

@@ -1,4 +1,4 @@
import { z } from "zod";
import { z } from "zod/v4";
import { randomBytes } from "crypto";
export namespace Identifier {
@@ -11,7 +11,7 @@ export namespace Identifier {
return z.string().startsWith(prefixes[prefix]);
}
const LENGTH = 24;
const LENGTH = 26;
export function ascending(prefix: keyof typeof prefixes, given?: string) {
return generateID(prefix, false, given);
@@ -45,6 +45,11 @@ export namespace Identifier {
const randLength = (LENGTH - 12) / 2;
const random = randomBytes(randLength);
return prefix + "_" + timeBytes.toString("hex") + random.toString("hex");
return (
prefixes[prefix] +
"_" +
timeBytes.toString("hex") +
random.toString("hex")
);
}
}