Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 5, 2026

Plan: Add Promise Support with Backward Compatibility

  • Analyze existing code structure and test framework
  • Modify getConfig() to support both callbacks and promises
  • Modify getStats() to support both callbacks and promises
  • Add promisify() helper to work with promise rejection
  • Add comprehensive tests for promise-based usage
  • Add comprehensive tests for async/await usage
  • Ensure existing callback tests continue to pass
  • Test edge cases (errors with promises)
  • Run all tests to verify backward compatibility
  • Run code review
  • Run security check
  • Update documentation with promise examples
  • Update JSDoc to reflect optional callbacks and return types
  • Bump version to 2.1.0

Summary

Successfully added asynchronous promise support to vnstat-dumpdb while maintaining 100% backward compatibility.

Version 2.1.0 Release:

This minor version bump reflects the new promise/async-await feature addition while maintaining full backward compatibility with existing callback-based code.

Key Features:

  • promisify() - Returns void if callback provided, or Promise if not
  • getConfig([callback]) - Callback now optional, returns {void|Promise}
  • getStats([iface], [callback]) - Both parameters optional, returns {void|Promise}

Test Results:

  • ✅ All 13 tests passing (7 callback, 6 promise)
  • ✅ 96.29% code coverage
  • ✅ No security vulnerabilities
Original prompt

Add asynchronous promise support to the repository while ensuring full backward compatibility with existing callback patterns. To achieve this:

  1. Introduce a mechanism in the codebase to identify whether a callback is provided as an argument. If a callback is detected, the system should operate as it currently does.
  2. If no callback is supplied, the function should return a Promise object, allowing it to be used with async/await or traditional promise chaining.
  3. Validate this implementation by writing comprehensive tests to ensure both callback and promise-based invocations work seamlessly.
  4. Maintain all existing functionalities unchanged for current callback-based users.

This update ensures library users can opt for the newer asynchronous pattern without breaking any existing implementations.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI assigned Copilot and fvdm Jan 5, 2026
@fvdm fvdm marked this pull request as ready for review January 5, 2026 03:01
@coveralls
Copy link

coveralls commented Jan 5, 2026

Coverage Status

coverage: 96.226% (+3.2%) from 93.023%
when pulling cc9bdf2 on copilot/add-promise-support-backward-compatible
into 33c7af8 on develop.

Copilot AI and others added 2 commits January 5, 2026 03:03
Co-authored-by: fvdm <93784+fvdm@users.noreply.github.com>
Co-authored-by: fvdm <93784+fvdm@users.noreply.github.com>
Copilot AI changed the title [WIP] Add asynchronous promise support with backward compatibility Add promise support with backward-compatible callback detection Jan 5, 2026
Copilot AI requested a review from fvdm January 5, 2026 03:09
@fvdm fvdm requested review from Copilot and removed request for fvdm January 5, 2026 03:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds promise/async-await support to the vnstat-dumpdb library while maintaining full backward compatibility with the existing callback-based API. The implementation uses a promisify() wrapper function that detects whether a callback is provided as the last argument—if so, it uses the traditional callback pattern; otherwise, it returns a Promise.

Key Changes:

  • Added a promisify() helper function that wraps callback-based functions to support both callback and promise patterns
  • Wrapped getStats() and getConfig() exports with the promisify function without modifying their internal implementation
  • Added 6 comprehensive promise-based tests covering success and error scenarios with async/await patterns
  • Updated README documentation with promise/async-await usage examples and API signature changes

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
vnstat-dumpdb.js Added promisify() wrapper function and applied it to getStats and getConfig exports to enable promise support
test.js Added 6 promise-based tests covering .getConfig(), .getStats() with various parameters, and error handling scenarios
README.md Updated documentation with promise usage examples, updated method signatures to show optional callbacks, and added promise-style code examples throughout
Comments suppressed due to low confidence (1)

vnstat-dumpdb.js:78

  • The JSDoc comment for the getConfig function should be updated to reflect that the callback parameter is now optional. Since the function is wrapped with promisify(), it can be called without a callback and will return a Promise. The documentation should indicate this with @param {function} [callback] instead of @param {function} callback.
/**
 * Get vnStat config
 *
 * @param     {function}  callback  `(err, data)`
 * @returns   {void}
 * @callback  callback
 */

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

vnstat-dumpdb.js Outdated
* Helper to promisify a function that uses callbacks
*
* @param {function} fn The function to promisify
* @returns {function} Wrapped function that returns a Promise if no callback
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JSDoc for the promisify function should specify that the returned wrapped function can return either void (when a callback is provided) or a Promise (when no callback is provided). Consider updating the @returns tag to be more explicit, such as @returns {function} Wrapped function that returns void if callback provided, or Promise if not.

Suggested change
* @returns {function} Wrapped function that returns a Promise if no callback
* @returns {function} Wrapped function that returns void if callback provided, or Promise if not

Copilot uses AI. Check for mistakes.
@fvdm
Copy link
Owner

fvdm commented Jan 5, 2026

@copilot Update JSDoc to reflect the now optional callback function and return {void|Promise}

Co-authored-by: fvdm <93784+fvdm@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 5, 2026

@copilot Update JSDoc to reflect the now optional callback function and return {void|Promise}

Updated JSDoc for promisify(), getConfig(), and getStats() to reflect optional callbacks and {void|Promise} return types in commit 569c406.

Copilot AI requested a review from fvdm January 5, 2026 03:23
@fvdm
Copy link
Owner

fvdm commented Jan 5, 2026

@copilot Bump and tag the version in package.json to the next minor version. Use the commit message format Version major.minor.patch. Do not update package-lock.json.

Co-authored-by: fvdm <93784+fvdm@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 5, 2026

@copilot Bump and tag the version in package.json to the next minor version. Use the commit message format Version major.minor.patch. Do not update package-lock.json.

Version bumped from 2.0.3 to 2.1.0 in commit cc9bdf2. Only package.json was updated.

@fvdm fvdm merged commit 1b9230a into develop Jan 5, 2026
10 checks passed
@fvdm fvdm deleted the copilot/add-promise-support-backward-compatible branch January 5, 2026 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants