CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/npm-ulid

tessl install tessl/npm-ulid@3.0.0

A universally-unique, lexicographically-sortable, identifier generator

Agent Success

Agent success rate when using this tile

78%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.34x

Baseline

Agent success rate without this tile

58%

task.mdevals/scenario-6/

Event ID Generator

Build a system that generates unique, sortable identifiers for events in a distributed logging platform.

Requirements

Your task is to implement an event ID generation system that:

  1. Generates unique identifiers for incoming events
  2. Ensures identifiers are lexicographically sortable by their creation time
  3. Handles events that may arrive with custom timestamps (for example, when ingesting historical logs)
  4. Provides a way to verify that generated identifiers are properly formatted

Implementation

@generates

API

/**
 * Generate a unique event identifier using the current timestamp
 * @returns A unique event identifier string
 */
export function generateEventId(): string;

/**
 * Generate a unique event identifier using a specific timestamp
 * @param timestamp - Unix timestamp in milliseconds
 * @returns A unique event identifier string
 */
export function generateEventIdWithTimestamp(timestamp: number): string;

/**
 * Validate whether a string is a properly formatted event identifier
 * @param id - The string to validate
 * @returns true if valid, false otherwise
 */
export function isValidEventId(id: string): boolean;

Test Cases

Generates event IDs

  • Calling generateEventId() returns a 26-character string @test
  • Calling generateEventId() twice returns different identifiers @test

Generates event IDs with timestamps

  • Calling generateEventIdWithTimestamp(1234567890000) returns a 26-character string @test
  • Event IDs generated with earlier timestamps sort before those with later timestamps: generateEventIdWithTimestamp(1000) < generateEventIdWithTimestamp(2000) @test

Validates event IDs

  • isValidEventId("01ARZ3NDEKTSV4RRFFQ69G5FAV") returns true @test
  • isValidEventId("invalid123") returns false @test
  • isValidEventId("") returns false @test

Dependencies { .dependencies }

ulid { .dependency }

Provides unique, lexicographically sortable identifier generation.

@satisfied-by

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/ulid@3.0.x
tile.json