Skip to content

Conversation

@galligan
Copy link
Contributor

Uses Bun.hash() with base62 encoding for URL-safe, collision-resistant
short IDs. Configurable length (default 5 chars, ~916M combinations).

Closes #46

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

Copy link
Contributor Author

galligan commented Jan 23, 2026

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@galligan galligan force-pushed the p3-7/contracts/logger-child branch from 8d043eb to 62826b8 Compare January 23, 2026 11:58
@galligan galligan added the enhancement New feature or request label Jan 23, 2026
@galligan galligan marked this pull request as ready for review January 23, 2026 12:00
@greptile-apps
Copy link

greptile-apps bot commented Jan 23, 2026

Greptile Summary

  • Adds new hashId() function to @outfitter/types package that generates deterministic, URL-safe short identifiers using Bun.hash() with base62 encoding
  • Implements configurable length (default 5 characters, providing ~916M combinations) with proper padding and truncation
  • Includes comprehensive test suite following TDD principles with determinism, URL-safety, uniqueness, and edge case validation

Important Files Changed

Filename Overview
packages/types/src/hash-id.ts New module implementing hashId() with Bun.hash() and base62 encoding for deterministic short identifiers
packages/types/src/tests/hash-id.test.ts Comprehensive test suite covering determinism, configurability, URL-safety, uniqueness, and edge cases

Confidence score: 4/5

  • This PR is safe to merge with only minor review needed for one implementation assumption
  • Score reflects solid test coverage and clean implementation, but one test assumes prefix consistency behavior that may not hold for all hash/encoding combinations
  • Pay close attention to the prefix consistency test in hash-id.test.ts to verify the assumption aligns with actual implementation behavior

Sequence Diagram

sequenceDiagram
    participant User
    participant hashId
    participant Bun
    participant toBase62

    User->>hashId: "hashId('user-123', 8)"
    hashId->>Bun: "Bun.hash('user-123')"
    Bun-->>hashId: "64-bit hash number"
    hashId->>toBase62: "toBase62(BigInt(hash))"
    toBase62-->>hashId: "base62 string"
    hashId->>hashId: "padStart(8, '0')"
    hashId->>hashId: "slice(0, 8)"
    hashId-->>User: "URL-safe hash ID"
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

Comment on lines +135 to +147
it("same input with different lengths produces consistent prefixes", () => {
// Longer hashes should be extensions of shorter ones
// (this tests that the algorithm is consistent)
const input = "consistent-test";
const short = hashId(input, 3);
const medium = hashId(input, 6);
const long = hashId(input, 10);

// The shorter hash should be a prefix of longer ones
expect(medium.startsWith(short)).toBe(true);
expect(long.startsWith(short)).toBe(true);
expect(long.startsWith(medium)).toBe(true);
});
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: This test assumes that longer hashes are extensions of shorter ones, but this may not hold true depending on how the base62 encoding is implemented. If the encoding uses modular arithmetic or truncation after encoding, this assumption could fail. Does the hashId implementation guarantee that longer results will always be prefixes of shorter ones for the same input?

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/types/src/__tests__/hash-id.test.ts
Line: 135:147

Comment:
**logic:** This test assumes that longer hashes are extensions of shorter ones, but this may not hold true depending on how the base62 encoding is implemented. If the encoding uses modular arithmetic or truncation after encoding, this assumption could fail. Does the hashId implementation guarantee that longer results will always be prefixes of shorter ones for the same input?

How can I resolve this? If you propose a fix, please make it concise.

Uses Bun.hash() with base62 encoding for URL-safe, collision-resistant
short IDs. Configurable length (default 5 chars, ~916M combinations).

Closes #46

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@galligan galligan changed the base branch from p3-7/contracts/logger-child to graphite-base/70 January 23, 2026 21:22
@galligan galligan changed the base branch from graphite-base/70 to p3-7/contracts/logger-child January 23, 2026 21:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants