CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-update-notifier

Update notifications for your CLI app

Overall
score

97%

Overview
Eval results
Files

task.mdevals/scenario-6/

Package Update Monitor

Build a class-based package update monitoring system that checks for updates and stores check history with proper data encapsulation.

Requirements

Create a PackageMonitor class that tracks update checks for a package and stores historical check data. The class should:

  1. Accept package name and current version during initialization
  2. Provide a method to record an update check with a timestamp and the latest version found
  3. Provide a method to retrieve the most recent check information
  4. Provide a method to get the total count of checks performed
  5. Ensure internal state cannot be modified directly from outside the class

The class should properly encapsulate its internal data, preventing external code from directly accessing or modifying the check history and package information.

Implementation

@generates

API

/**
 * Monitors package updates with proper data encapsulation
 */
class PackageMonitor {
  /**
   * Creates a new PackageMonitor instance
   * @param {string} packageName - The name of the package to monitor
   * @param {string} currentVersion - The current version of the package
   */
  constructor(packageName, currentVersion) {}

  /**
   * Records an update check
   * @param {string} latestVersion - The latest version found during the check
   * @returns {void}
   */
  recordCheck(latestVersion) {}

  /**
   * Gets the most recent check information
   * @returns {Object|null} Object with {timestamp, latestVersion} or null if no checks
   */
  getLastCheck() {}

  /**
   * Gets the total number of checks performed
   * @returns {number} The count of checks
   */
  getCheckCount() {}

  /**
   * Gets the package name (read-only access)
   * @returns {string} The package name
   */
  getPackageName() {}

  /**
   * Gets the current version (read-only access)
   * @returns {string} The current version
   */
  getCurrentVersion() {}
}

module.exports = { PackageMonitor };

Test Cases

Basic Functionality

  • Creating a PackageMonitor with name "test-pkg" and version "1.0.0" stores the package information and can be retrieved via getPackageName() and getCurrentVersion() @test
  • Recording a check with version "1.1.0" and then calling getLastCheck() returns an object with the latest version and a timestamp @test
  • Recording three checks and calling getCheckCount() returns 3 @test
  • Calling getLastCheck() before any checks have been recorded returns null @test

Encapsulation

  • The internal check history cannot be accessed or modified directly from outside the class @test
  • Modifying the object returned by getLastCheck() does not affect subsequent calls to getLastCheck() @test

Dependencies { .dependencies }

update-notifier { .dependency }

Provides inspiration for class-based architecture patterns and encapsulation techniques used in update monitoring systems.

Install with Tessl CLI

npx tessl i tessl/npm-update-notifier

tile.json