Repository navigation
feat(uniku): derive stable IDs with name-based uuid/v5 - #106
Merged
Merged
Conversation
Derive a stable RFC 9562 UUID v5 from a name and namespace with a synchronous, dependency-free SHA-1. Adds uuidv5.namespace() to parse a namespace once, plus the DNS, URL, OID, and X500 namespace constants.
Add --name and --namespace (dns, url, oid, x500, or a UUID) for name-based UUIDs, and recognize v5 IDs in inspect and validate.
Check the RFC 9562 vector on Node, Bun, Deno, browsers, and Cloudflare Workers, add v5 generation and validation benchmarks against npm uuid, assert in publish-smoke that each entry point imports no other generator, and restart the rolling benchmark baseline when the benchmark set changes.
Add the UUID v5 reference page and cover derived IDs in the choosing guide, uuid migration guide, stability contract, and entry point lists.
Document that lone surrogates hash as U+FFFD, cover name and namespace bytes aliasing the output buffer, and make the publish-smoke isolation check follow bare uniku/* self-imports too.
Contributor
|
Preview removed because the pull request was closed. |
@effect/[email protected] depends on platform-node-shared ^4.0.0-beta.93, which npm now resolves to 4.1.3. That version imports effect modules missing from [email protected], so a global npm install of @uniku/cli crashed on startup. A direct exact dependency makes npm dedupe the transitive to the pinned beta.
commit: |
Contributor
Benchmark ResultsGeneration
Validation
Cold Start (Node)
Comparison vs Main
Bundle Impact
*Excludes external dependencies (e.g., @noble/hashes) Generated by workflow run 42925049527 |
jkomyno
commented
Nov 10, 2026
jkomyno
left a comment
Owner
Author
There was a problem hiding this comment.
Two issues to fix before merging and cutting the minor release. A bound UUID v5 namespace can change after construction when supplied as a Node.js Buffer. The Changesets plan also leaves the CLI at its current version, so the documented UUID v5 command and npm startup fix would stay out of the published CLI.
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
uniku can now derive a stable ID from an identifier you already hold:
uniku/uuid/v5returns the same RFC 9562 UUID v5 for the same name and namespace in every process and runtime, with no state to keep. The CLI exposes it asuniku uuid -v 5 --namespace <dns|url|oid|x500|uuid> --name <value>.Fixes #105
Decisions on the issue's open questions
uuidpackage. Lone surrogates hash as U+FFFD, whereuuidthrows instead. Both behaviors are pinned by tests, documented, and listed inSTABILITY.mdas fixed for 1.x.timestamp(), as onuuid/v4.TypeID. The issue's
typeid.fromUuid('sess', uuidv5(...))now works. The TypeID spec (v0.3.0) only requires generated TypeIDs to be UUID v7, and says implementations SHOULD encode and decode other versions. uniku rejected 8 of the spec's 9 valid test vectors withUUID_NOT_V7, including nil and max. Now:fromUuid,fromBytes,toUuid,toBytes,prefix,suffixandisValidaccept any 128-bit value, which matchestypeid-js.typeid()still generates UUID v7.typeid.timestamp()is the only function that throwsUUID_NOT_V7, for a TypeID that does not wrap a UUID v7.fromUuidwith a string that is not a UUID now throwsParseError(INVALID_LENGTH,INVALID_FORMATorINVALID_CHAR, strategytypeid) instead ofUUID_NOT_V7. This has its own minor changeset.Errors. No new error codes. A malformed namespace string throws
ParseError, namespace bytes that are not 16 long throwInvalidInputError(BYTES_INVALID_LENGTH), and a bad offset throwsBufferError. Values outside the TypeScript signatures, such asnull, still throw a nativeTypeError, as they do in every other generator.CLI.
-v 5requires both--nameand--namespace. Either flag with v4 or v7 is a usage error, and so is-nabove 1, because every output would be the same ID.uniku inspectanduniku validatenow report v5 IDs as UUID v5. Before, auto-detection classified them as Nanoid.Changes outside the new module
publish-smokenow fails if any packed generator imports another generator's module, following both relative and bareuniku/*imports. The two existing generator-to-generator imports are allowed by name:typeidusesuuid/v7, andcuid/v2usescuid2. I checked it catches a planteduniku/uuid/v4import in the built v5 file.mergeBenchmarkHistorynow drops baseline entries measured on a different set of benchmarks, so the rolling window restarts. Without this, the new v5 benchmark rows would make the baseline job throwBenchmark matrix mismatchon the first push to main.npm i -g @uniku/clicrashed on startup, and so did CI's global-install check, until this PR.@effect/[email protected]accepts@effect/platform-node-shared@^4.0.0-beta.93, and npm now resolves that range to4.1.3, which imports aneffectmodule that the pinned4.0.0-beta.93does not have. The CLI now depends on@effect/[email protected]directly, so npm reuses that version. This was already broken before this PR and showed up because CI had not run since August.uniku validateanduniku inspectreport the UUID version a TypeID wraps. They used to hard-code v7. Inspecting a non-v7 TypeID shows no timestamp and adds a note. Auto-detection still treats a prefixless TypeID as a ULID unless it wraps a UUID v7, because every lowercase ULID is also a valid prefixless TypeID.Bufferin the library. A Biome rule now rejects theBufferglobal andbuffer/node:bufferimports inpackages/uniku/src.uuidv5.namespace()copies namespace bytes withnew Uint8Array(...), because.slice()on a caller'sBufferreturns a view of the same memory.@uniku/cliis out of the Changesets ignore list, which it joined in August for the library-only 0.6.0 release. A patch changeset shipsuuid -v 5and the npm install fix as@uniku/cli0.7.1. The move to Effect 4.1.x and a CLI minor release is Release a @uniku/cli minor version on Effect 4.1.x #107.performance.mdx. Several existing sizes were stale, for exampletypeidanderrors.Performance
Local runs on Node 25, uniku against the
uuidpackage'sv5. These are directional numbers. The CI benchmark comment on this PR shows 3.1x, 2x, and 1.8x for the same three rows.uuid'www.example.com'uuidv5.namespace()runs at about 2.36M ops/s, against 1.13M for the two-argument call, because the two-argument call parses the namespace string each time. The library does not cache it, as the issue asks. The builtuuid/v5entry is about 1.8 KB. The UUID parser now takes the error strategy as a parameter, which adds 9 bytes gzipped to the UUID entries and movesuuid/v7from ~1.6 KB to ~1.7 KB in the table. TypeID shrinks by 28 bytes.Verification
node:cryptoSHA-1 check for every name length from 0 to 200 bytes, which crosses each padding boundary, plus names of 10,000 and 70,000 bytesnamespace()keeping its own copy of the namespace bytesuuid@14v5with random Unicode and byte names and random namespaces.valid.ymlandinvalid.ymlvectors, and an integration test checks UUID v4, v5 and v7 conversions againsttypeid-js.pnpm test(547 uniku tests, 256 CLI tests),pnpm typecheck,pnpm lint:ci, the docs typecheck and build, publish smoke, attw, and publint all pass.Not included, as the issue's out-of-scope list says: a cache, HMAC-keyed derivation, and a SHA-256 variant. The meta tags in
apps/docs/src/routes/__root.tsxstill say "ten" strategies. That file had unrelated uncommitted edits, so I left it out of this PR.