2.48.0 • Published 5 months ago

@memberjunction/doc-utils v2.48.0

Weekly downloads
-
License
ISC
Repository
-
Last release
5 months ago

MemberJunction Documentation Utilities

A TypeScript library for dynamically retrieving, parsing, and caching MemberJunction library documentation from the official documentation website to support AI models and other documentation-driven features.

Overview

The @memberjunction/doc-utils package provides functionality for accessing the official MemberJunction documentation. It fetches documentation from the MemberJunction documentation site (https://memberjunction.github.io/MJ/), parses the HTML content, and caches library documentation in memory for improved performance. This library is particularly useful when integrating with AI models that need context about the MemberJunction system's libraries and their components.

Installation

npm install @memberjunction/doc-utils

Dependencies

This package depends on the following MemberJunction packages:

  • @memberjunction/core - Core functionality and base classes
  • @memberjunction/core-entities - Entity definitions
  • @memberjunction/global - Global utilities and decorators

External dependencies:

  • jsdom - For HTML parsing
  • axios - For HTTP requests

Main Features

  • Library Documentation Retrieval: Dynamically fetch documentation for MemberJunction libraries and their items
  • HTML Content Parsing: Extract relevant content from HTML documentation pages
  • Automatic URL Generation: Constructs documentation URLs based on library and item metadata
  • Extended Entity Classes: Provides extended functionality for Library and Library Item entities
  • Singleton Pattern: Easy access to documentation functionality throughout your application
  • Type-aware URL Routing: Automatically routes to correct documentation sections based on item type (Class, Interface, Function, etc.)

Usage

Basic Example

import { DocumentationEngine } from '@memberjunction/doc-utils';
import { UserInfo } from '@memberjunction/core';

// Get the singleton instance
const docEngine = DocumentationEngine.Instance;

// Configure the engine (required before using)
const user = new UserInfo(); // Or get from your authentication context
await docEngine.Config(false, user);

// Access libraries and their documentation
const libraries = docEngine.Libraries;
console.log(`Found ${libraries.length} libraries`);

// Access specific library items
const coreLibrary = libraries.find(lib => lib.Name === '@memberjunction/core');
if (coreLibrary) {
    console.log(`Library: ${coreLibrary.Name}`);
    console.log(`Items: ${coreLibrary.Items.length}`);
    
    // Access documentation for specific items
    coreLibrary.Items.forEach(item => {
        console.log(`${item.Type}: ${item.Name}`);
        console.log(`URL: ${item.URL}`);
        console.log(`Content Preview: ${item.HTMLContent.substring(0, 200)}...`);
    });
}

Working with Library Items

import { DocumentationEngine } from '@memberjunction/doc-utils';

async function displayLibraryItemInfo(libraryName: string, itemName: string) {
    const docEngine = DocumentationEngine.Instance;
    await docEngine.Config();
    
    // Find all library items
    const libraryItems = docEngine.LibraryItems;
    
    // Find specific item
    const item = libraryItems.find(i => 
        i.Library === libraryName && i.Name === itemName
    );
    
    if (item) {
        console.log(`Item: ${item.Name}`);
        console.log(`Type: ${item.Type}`);
        console.log(`Library: ${item.Library}`);
        console.log(`Documentation URL: ${item.URL}`);
        console.log(`HTML Content Available: ${item.HTMLContent ? 'Yes' : 'No'}`);
    }
}

// Example usage
await displayLibraryItemInfo('@memberjunction/core', 'BaseEntity');

Force Refresh Documentation

import { DocumentationEngine } from '@memberjunction/doc-utils';

// Force refresh to reload documentation from the database and website
const docEngine = DocumentationEngine.Instance;
await docEngine.Config(true); // true forces a refresh

API Reference

DocumentationEngine

The main class that provides access to documentation functionality. Extends BaseEngine from @memberjunction/core.

Properties

  • Instance (static): Returns the singleton instance of DocumentationEngine
  • Libraries: Array of LibraryEntityExtended objects containing all loaded libraries
  • LibraryItems: Array of LibraryItemEntityExtended objects containing all library items

Methods

  • Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>
    • Configures the documentation engine and loads metadata
    • Parameters:
      • forceRefresh: If true, forces reload of metadata from database
      • contextUser: User context for server-side execution
      • provider: Optional metadata provider

LibraryEntityExtended

Extended entity class for libraries with documentation capabilities.

Properties

  • All properties from LibraryEntity
  • Items: Array of LibraryItemEntityExtended objects belonging to this library

LibraryItemEntityExtended

Extended entity class for library items with documentation capabilities.

Properties

  • All properties from LibraryItemEntity
  • URL: The generated documentation URL for this item
  • HTMLContent: The parsed HTML content from the documentation
  • TypeURLSegment: Returns the URL segment based on item type (classes, interfaces, functions, etc.)

Supported Item Types

  • Class → /classes/
  • Interface → /interfaces/
  • Function → /functions/
  • Module → /modules/
  • Type → /types/
  • Variable → /variables/

Integration with MemberJunction

This package integrates seamlessly with the MemberJunction ecosystem:

  1. Entity System: Uses MemberJunction's entity system for Library and Library Items metadata
  2. Base Engine Pattern: Extends BaseEngine for consistent configuration and loading patterns
  3. Global Registration: Uses @RegisterClass decorator for proper entity registration
  4. User Context: Supports MemberJunction's user context for server-side execution

Build and Development

# Build the package
npm run build

# Run in development mode with hot reload
npm start

# Run tests (when implemented)
npm test

Notes

  • The documentation engine fetches content from https://memberjunction.github.io/MJ/
  • Documentation is cached in memory after initial load for performance
  • The engine automatically constructs URLs based on library names and item types
  • Library names with special characters (@, ., /, ) are sanitized for URL compatibility

License

ISC

2.27.1

8 months ago

2.23.2

9 months ago

2.46.0

5 months ago

2.23.1

9 months ago

2.27.0

8 months ago

2.34.0

6 months ago

2.30.0

7 months ago

2.19.4

9 months ago

2.19.5

9 months ago

2.19.2

9 months ago

2.19.3

9 months ago

2.19.0

9 months ago

2.19.1

9 months ago

2.15.2

9 months ago

2.34.2

6 months ago

2.15.0

9 months ago

2.34.1

6 months ago

2.15.1

9 months ago

2.38.0

5 months ago

2.45.0

5 months ago

2.22.1

9 months ago

2.22.0

9 months ago

2.41.0

5 months ago

2.22.2

9 months ago

2.26.1

8 months ago

2.26.0

8 months ago

2.33.0

6 months ago

2.18.3

9 months ago

2.18.1

9 months ago

2.18.2

9 months ago

2.18.0

9 months ago

2.37.1

6 months ago

2.37.0

6 months ago

2.14.0

10 months ago

2.21.0

9 months ago

2.44.0

5 months ago

2.40.0

5 months ago

2.29.0

8 months ago

2.29.2

8 months ago

2.29.1

8 months ago

2.25.0

8 months ago

2.48.0

5 months ago

2.32.0

7 months ago

2.32.2

7 months ago

2.32.1

7 months ago

2.17.0

9 months ago

2.13.4

10 months ago

2.36.0

6 months ago

2.13.2

11 months ago

2.13.3

10 months ago

2.13.0

11 months ago

2.36.1

6 months ago

2.13.1

11 months ago

2.43.0

5 months ago

2.20.2

9 months ago

2.20.3

9 months ago

2.20.0

9 months ago

2.20.1

9 months ago

2.28.0

8 months ago

2.47.0

5 months ago

2.24.1

8 months ago

2.24.0

8 months ago

2.31.0

7 months ago

2.12.0

12 months ago

2.39.0

5 months ago

2.16.1

9 months ago

2.35.1

6 months ago

2.35.0

6 months ago

2.16.0

9 months ago

2.42.1

5 months ago

2.42.0

5 months ago

2.23.0

9 months ago

2.11.0

1 year ago

2.10.0

1 year ago

2.9.0

1 year ago

2.8.0

1 year ago

2.7.0

1 year ago

2.6.1

1 year ago

2.5.2

1 year ago

2.6.0

1 year ago

2.7.1

1 year ago

2.5.1

1 year ago

2.5.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.3.3

1 year ago

2.3.2

1 year ago

2.3.1

1 year ago

2.3.0

1 year ago

2.2.1

1 year ago

2.2.0

1 year ago

2.1.5

1 year ago

2.1.4

1 year ago

2.1.3

1 year ago

2.1.2

1 year ago

2.1.1

1 year ago

2.1.0

1 year ago

2.0.0

1 year ago

1.8.1

1 year ago

1.8.0

1 year ago

1.7.1

1 year ago

1.7.0

1 year ago

1.6.1

1 year ago

1.6.0

1 year ago

1.5.3

1 year ago

1.5.2

1 year ago

1.5.1

1 year ago

1.5.0

1 year ago

1.4.1

1 year ago