Extract shared timestamp-id primitives into TimestampId module#2629
Extract shared timestamp-id primitives into TimestampId module#2629maeldonn wants to merge 8 commits into
Conversation
Replace the random 8-byte hex microVersionId with a 20-character timestamp-ordered identifier matching the versionId scheme, and add encode/decode/compare helpers in a new MicroVersionID module. Add an optional isReplica flag to ReplicationInfo to distinguish replica writes from user writes, enabling cascaded CRR. Issue: ARSN-578
Issue: ARSN-578
Move the constants, padding/hex helpers, and the stateful ts+seq+rg generator out of VersionID into a new TimestampId module that both VersionID and MicroVersionId consume. Each module instantiates its own generator so the two id streams keep independent counters. Add a dedicated test suite covering constants, helpers, and generator behaviour. Issue: ARSN-583
Replace the template+slice padding pattern with native padStart/padEnd in TimestampId, and modernize the constants (10**N, '0'.repeat). Remove the backward-compatibility re-exports from VersionID so callers must import shared primitives from TimestampId directly. Issue: ARSN-583
The 1ms wait guarding against pre-crash id collisions protects the process, not the closure, so each generator was paying it again unnecessarily. Move the guard to a module-level flag, drop the now redundant inline comments at the call sites, and collapse the MicroVersionId generate wrapper since it added no logic over the underlying closure. Issue: ARSN-583
Drop the fictional version parameter from hasVersionIDFormat (only ever called with VERSION_ID_FORMAT_VERSION), rename it to hasCurrentFormatSuffix to match what it actually verifies, and replace the hand-rolled marker+version compare with a single endsWith call on the precomputed suffix constant. Issue: ARSN-583
decode now uses TimestampId.parse to validate the decoded id structure, adding a numeric ts/seq check on top of the existing length guard. compare becomes a pure re-export from TimestampId instead of a one-line wrapper, since the function is identical. Issue: ARSN-583
| hexDecode, | ||
| createTimestampSequenceGenerator, | ||
| getInfId, | ||
| } from './TimestampId'; |
There was a problem hiding this comment.
VersionID.ts previously exported hexEncode, hexDecode, padLeft, padRight, wait, MAX_TS, MAX_SEQ, LENGTH_TS, LENGTH_SEQ, LENGTH_RG, TEMPLATE_TS, TEMPLATE_SEQ, TEMPLATE_RG. These are now only in TimestampId.ts, which is not re-exported from lib/versioning/index.ts.
Since index.ts does export * as VersionID from './VersionID', downstream consumers (CloudServer, Backbeat) accessing e.g. versioning.VersionID.hexEncode will break at import time.
Consider re-exporting the moved symbols from VersionID.ts (e.g. export { hexEncode, hexDecode, padLeft, padRight, wait, MAX_TS, MAX_SEQ, LENGTH_TS, LENGTH_SEQ, LENGTH_RG, TEMPLATE_TS, TEMPLATE_SEQ, TEMPLATE_RG } from './TimestampId') or exporting TimestampId from lib/versioning/index.ts and coordinating the migration with downstream repos.
— Claude Code
|
5f4839a to
7be6414
Compare
Move the constants, padding/hex helpers, and the stateful ts+seq+rg
generator out of VersionID into a new TimestampId module that both
VersionID and MicroVersionId consume. Add
a dedicated test suite covering constants, helpers, and generator
behaviour.
Issue: ARSN-583