```ts
/**
 * A fixed-capacity least-recently-used cache.
 */
export class LruCache<K, V> {
  /** @private */ private readonly capacity: number;
  /** @private */ private readonly map: Map<K, V>;

  /**
   * Creates a new LRU cache with the given positive integer capacity.
   * @throws Error if capacity is not a positive integer.
   */
  constructor(capacity: number) {
    if (!Number.isInteger(capacity) || capacity <= 0) {
      throw new Error("capacity must be a positive integer");
    }
    this.capacity = capacity;
    this.map = new Map<K, V>();
  }

  /**
   * Returns the value associated with the key or undefined if not found.
   * If the key exists, it is marked as recently used.
   */
  get(key: K): V | undefined {
    const value = this.map.get(key);
    if (value !== undefined) {
      // Move to end to mark as recently used
      this.map.delete(key);
      this.map.set(key, value