Skip to content

Add JSDoc annotations to enable auto-generated API docs and type definitions #598

@oberstet

Description

@oberstet

Summary

Add comprehensive JSDoc annotations to the AutobahnJS source code to enable:

  1. Auto-generated API documentation via sphinx-js
  2. TypeScript .d.ts type definition generation (Track A from AutobahnJS v26.1.1 Release #595)

Background

The v26.1.1 documentation infrastructure uses Sphinx with the Furo theme, deployed to GitHub Pages. We initially planned to use sphinx-js for auto-generated JavaScript API documentation, but this requires JSDoc annotations in the source code.

Currently, the AutobahnJS codebase has minimal JSDoc comments. The docs/api/index.rst was converted to a manual API reference as a workaround (see commit 39e4f18).

Relationship to Track A: Type Definitions (#595)

JSDoc annotations are a prerequisite for Track A.

From #595, Track A's approach is:

  • Generate .d.ts type definition files from existing code
  • Add JSDoc type annotations where missing
  • Configure TypeScript in checkJs mode for validation
  • Do NOT rewrite codebase in TypeScript (high risk)

JSDoc annotations serve dual purposes:

Purpose Tool Benefit
API Documentation sphinx-js Auto-generated docs from source
Type Definitions TypeScript (tsc --declaration) Generate .d.ts files from JSDoc
Static Analysis TypeScript (checkJs mode) Type checking without migration

By adding JSDoc annotations, we enable both goals with a single effort:

  • sphinx-js reads JSDoc to generate Sphinx documentation
  • TypeScript reads JSDoc to generate .d.ts type definitions
  • TypeScript can validate types in CI without converting to .ts files

Scope

Files to Annotate

Priority 1: Public API (packages/autobahn/lib/)

  • connection.js — Connection class, options, callbacks
  • session.js — Session class, RPC/PubSub methods
  • autobahn.js — Main exports
  • serializer.js — Serializer classes
  • auth_cra.js — WAMP-CRA authentication

Priority 2: Internal Classes

  • transport/websocket.js — WebSocket transport
  • transport/rawsocket.js — RawSocket transport
  • util.js — Utility functions
  • log.js — Logging

Priority 3: XBR Extension (packages/autobahn-xbr/lib/)

  • autobahn-xbr.js — XBR exports
  • buyer.js, seller.js — Market participants
  • eip712.js — Ethereum signing

JSDoc Coverage Required

/**
 * Manages WebSocket connection and WAMP session lifecycle.
 * @class
 * @param {Object} options - Connection options
 * @param {string} options.url - WebSocket URL (e.g., 'ws://localhost:8080/ws')
 * @param {string} options.realm - WAMP realm to join
 * @param {string[]} [options.authmethods] - Authentication methods
 * @param {string} [options.authid] - Authentication ID
 * @param {Function} [options.onchallenge] - Challenge callback
 * @param {number} [options.max_retries=15] - Maximum reconnection attempts
 * @example
 * const connection = new autobahn.Connection({
 *     url: 'ws://localhost:8080/ws',
 *     realm: 'realm1'
 * });
 */
function Connection(options) {
    // ...
}

/**
 * Open the connection to the WAMP router.
 * @returns {void}
 */
Connection.prototype.open = function() {
    // ...
};

Implementation Plan

Phase 1: Core Public API

  1. Annotate Connection class with all options
  2. Annotate Session class with RPC/PubSub methods
  3. Annotate serializer classes
  4. Annotate authentication functions
  5. Re-enable sphinx-js in docs/conf.py
  6. Verify docs build with auto-generated API

Phase 2: Type Definition Generation

  1. Add tsconfig.json with allowJs, checkJs, declaration options
  2. Run tsc --declaration to generate .d.ts files
  3. Add .d.ts files to npm package
  4. Add TypeScript validation to CI

Phase 3: Internal Classes & XBR

  1. Annotate transport classes
  2. Annotate utility functions
  3. Annotate XBR extension classes

Acceptance Criteria

  • All public API functions/classes have JSDoc annotations
  • sphinx-js generates API docs without errors
  • TypeScript can generate .d.ts files from JSDoc
  • tsc --checkJs passes in CI
  • npm package includes .d.ts type definitions

References

Target

v26.2.1 or later — This is foundational work that enables both improved documentation and Track A type definitions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions