```ts
/**
 * A fixed-capacity least-recently-used cache.
 */
export class LruCache<K, V> {
  private readonly capacity: number;
  private readonly map = new 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;
  }

  /**
   * Retrieves the value for the given key, or undefined if not present.
   * Marks the key as recently used if it exists.
   */
  get(key: K): V | undefined {
    const hasKey = this.map.has(key);
    if (!hasKey) return undefined;

    const value = this.map.get(key)!;
    // Move to end to mark as most recently used
    this.map.delete(key);
    this.map.set(key, value);
    return value;
  }

  /**
   * Inserts or updates the key with the given value and marks it as recently used.
   * Evicts the least-recently-used entry if capacity would be exceeded.
   */
  set(key: K, value: V): void {
    const exists = this.map.has(key);
    if (exists) {
      // Update existing entry and move to end
      this.map.delete(key);
      this.map.set(key, value);
      return;
    }

    if (this.map.size >= this.capacity) {
      // Evict least recently used (first inserted)
      const lruKey = this.map.keys().next().value;
      this.map.delete(lruKey);
    }
    this.map.set(key, value);
  }

  /**
   * Current number of entries in the cache.
   */
  get size(): number {
    return this.map.size;
  }
}
```