CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-ulid

A universally-unique, lexicographically-sortable, identifier generator

78

1.34x
Overview
Eval results
Files

task.mdevals/scenario-3/

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

Install with Tessl CLI

npx tessl i tessl/npm-ulid

tile.json