Skip to content

chore: land PRs #117-#120 on main (stacked merges went into their base branches) - #123

Merged
jkomyno merged 5 commits into
mainfrom
chore/correct-stale-contracts
Nov 16, 2026
Merged

jkomyno merged 5 commits into
mainfrom
chore/correct-stale-contracts

Conversation

@jkomyno

@jkomyno jkomyno commented Nov 16, 2026

Copy link
Copy Markdown
Owner

⚠️ main only contains #116

All five PRs show as MERGED, but four of them were merged into their own base branch, not into main. GitHub's merge button targets the PR's base, and for a stack each base is the PR below it:

PR Base at merge time Merge commit landed on On main?
#116 main 128402c on main ✅
#117 fix/uuid-v4-randomuuid-guard e90172d on that branch ❌
#118 fix/uuid-versioned-tobytes 75ce468 on that branch ❌
#119 fix/unify-monotonic-overflow cc6551a on that branch ❌
#120 chore/correct-stale-contracts 997d020 on that branch ❌

So main has the secure-context fix for uniku/uuid/v4 and nothing else from the stack. Still missing:

  • uuidv7.timestamp() rejecting non-v7 UUIDs (UUID_NOT_V7), and the doc correction that toBytes() is a codec, not a version guard;
  • ULID's overflow policy unified with uuidv7, plus the 48-bit timestamp overflow fix that stopped ULID emitting 80000000000000000000000000 and stopped uuidv7 silently wrapping timestamps to zero;
  • the nanoid(0) / nanoid.isValid / STABILITY.md counter / stale-comment corrections;
  • the benchmark dispersion work and the rewritten performance page.

This PR is that reconciliation: 31 files, +589/−90, no new changes — just the four merged PRs' content, which is already reviewed and green. I verified docs/benchmark-honesty contributes nothing beyond chore/correct-stale-contracts, so nothing is stranded on the bottom branch either.

Please also hold #121

changeset-release/main (chore(release): version packages) is open against main and already consumed the only changeset there — the uuid/v4 patch from #116. Merging it now would publish 0.8.1 with one of five fixes, then produce a second release PR when this lands and the remaining four changesets appear. Merging this first folds all five changesets into one release.

If you would rather not use this PR

Equivalent outcomes: re-target #120/#119/#118/#117 to main before merging them (GitHub keeps them MERGED, so they cannot be re-opened — the branches are the only handle), or merge the branches directly. Deleting the stack branches after this lands is safe; deleting them before it loses four PRs' worth of work.

jkomyno and others added 5 commits November 16, 2026 03:03
`Crypto.randomUUID` is secure-context-only while `Crypto.getRandomValues` is
not, so an insecure browser origin exposes `crypto` with `randomUUID` missing.
The module captured `globalThis.crypto.randomUUID.bind(globalThis.crypto)` at
module scope, which threw during module evaluation there:

    TypeError: Cannot read properties of undefined (reading 'bind')

That took down the whole entry point, including `toBytes`, `fromBytes`, and
`isValid`, none of which touch randomness.

Resolve `randomUUID` once and guard it. The no-argument generator keeps using
`crypto.randomUUID()` where available and otherwise falls back to the shared
CSPRNG pool plus the local formatter, which is the path `_v4` already used.
`uuidv7.timestamp()` read its first six bytes through the version-agnostic byte
codec, so `uuidv7.timestamp(someV4)` returned a number that decodes to a
plausible date. `typeid.timestamp()` already refused that input with
`UUID_NOT_V7`; the two timestamp readers disagreed.

- `uuidv7.timestamp()` now requires the RFC 9562 version 7 and `10xx` variant
  bits and throws `InvalidInputError` with code `UUID_NOT_V7` otherwise. NIL and
  MAX still work, since RFC 9562 defines them without a version.
- Extract `isUuidVersion7` and `isNilOrMaxBytes` into `uuid/common/uuid.ts` and
  use them from both `uuid/v7` and `typeid`, so the two checks cannot drift.
- Document why `toBytes()` stays version-agnostic: it is a byte codec that has to
  parse arbitrary namespaces (the RFC v5 namespaces are version 1 UUIDs), while
  `isValid()` remains the version guard.

`UUID_NOT_V7` now lists `uuid` and `typeid` as strategies.
UUID v7 and ULID hit the same situation with two different answers. When the
per-time-unit sequence is exhausted, `uuidv7()` advanced its timestamp by one
millisecond and carried on; `ulid()` filled the remaining random bytes with
`0xff` and threw `RANDOM_OVERFLOW`, which also left every later call in that
millisecond failing.

Both now advance virtual time by one millisecond and continue from a zeroed
counter, so `incrementBytesInPlace` leaving the buffer at zero on overflow is
exactly the state the new bucket wants.

That unification exposed a bug both generators already had: neither bounded the
advance against the end of the 48-bit timestamp field. At the maximum
millisecond, uuidv7 wrote a timestamp that wrapped to zero, ULID's string path
emitted `80000000000000000000000000` (which its own `isValid()` rejects), and
ULID's buffer path also wrapped the timestamp. Both now saturate and throw
`TIMESTAMP_OUT_OF_RANGE`, and ULID keeps the `fill(0xff)` that makes the
saturated state fail closed on every later call.

`RANDOM_OVERFLOW` is removed from `ERROR_CODES`: the random-portion overflow now
recovers instead of failing, so there is no such failure to report. Pre-1.0, this
is a breaking change to the error surface; `migration/v1.mdx` documents the code
as removed with no replacement, and drops the `ULID_RANDOM_OVERFLOW` mapping.
Six small statements disagreed with the implementation. None changes a valid
input's output; two tighten input handling that was already documented as strict.

- `nanoid(0)` and `nanoid({ length: 0 })` returned `''` while the JSDoc advertised
  `@throws Length must be between 0 and 2048` and the CLI documented `1-256`.
  Length is now one integer check over `1..2048` with a single message. An empty
  string is never a usable identifier, and every other invalid length threw.
- `nanoid.isValid()` cannot check a generated length because a nanoid carries none.
  JSDoc and the reference page now say that outright instead of leaving the gap
  implicit for anyone reaching for it as a boundary validator.
- `nanoid` read the bare `crypto` global while every other module uses
  `globalThis.crypto`, which is the convention AGENTS.md states.
- `encodeBase62` and `encodeObjectIdHex` accepted over-long inputs and encoded only
  the leading bytes, while their public `fromBytes()` wrappers required the exact
  length. Both now require the exact length.
- `docs/STABILITY.md` called the ObjectID and XID counters "always-incrementing".
  Both wrap to zero after 2^24 values in the same second; the contract now says so.
- Corrected two comments: `incrementBytesInPlace` credited KSUID with a call it
  never makes, and the `objectid/hex.ts` decode-table note reported 128 KiB for a
  64 KiB allocation.
…120)

The performance guide reported every ratio to two significant figures with no
measure of uncertainty. The harness does not support that precision: the same row
moved between 1.2x and 1.6x across runs of the same command on one machine, and
the ULID row is 163x in the published CI snapshot versus ~85x on other hardware.

Reporting:

- `bench-summary` gains a `Spread` column built from each row's
  `withinActionRme`/`crossActionRme`, and reports `parity (within spread)` when a
  ratio's deviation from 1x is smaller than its own combined dispersion. A
  snapshot with no multi-run data prints `—` rather than an invented number.
- `benchmarkDispersion` and `combineDispersion` live in `bench-results.ts` next to
  the other statistics, prefer multi-run dispersion over a single run's RME, and
  combine independent dispersions in quadrature.
- The performance page reports ranges rounded to about one significant figure and
  says what each row does and does not compare: the UUID v4 row is a control that
  compares two identical `crypto.randomUUID()` calls, the TypeID/KSUID/TSID rows
  measure API shape as well as encoding, the ULID row is dominated by the
  reference re-detecting its PRNG per call, and every number is V8-only.

The bundle-size table is unchanged: it reproduces byte-for-byte with
`pnpm bundle:summary`, so it never had a precision problem.

Co-authored-by: jkomyno <[email protected]>
@github-actions

github-actions Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Preview removed because the pull request was closed.

@pkg-pr-new

pkg-pr-new Bot commented Nov 16, 2026

Copy link
Copy Markdown

Open in StackBlitz

pnpm add https://pkg.pr.new/@uniku/cli@123
pnpm add https://pkg.pr.new/uniku@123

commit: 997d020

@jkomyno
jkomyno merged commit 1e0b85f into main Nov 16, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant