@memberjunction/doc-utils 2.43.0 → 2.44.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/README.md +120 -67
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,10 +1,10 @@
1
1
  # MemberJunction Documentation Utilities
2
2
 
3
- A TypeScript library for dynamically retrieving, parsing, and caching MemberJunction documentation to support AI models and other documentation-driven features.
3
+ 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.
4
4
 
5
5
  ## Overview
6
6
 
7
- The `@memberjunction/doc-utils` package provides functionality for accessing the official MemberJunction documentation. It can fetch documentation from the MemberJunction object model documentation site, parse the HTML content, and cache elements in memory for improved performance. This library is particularly useful when integrating with AI models that need context about the MemberJunction system.
7
+ 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.
8
8
 
9
9
  ## Installation
10
10
 
@@ -15,9 +15,9 @@ npm install @memberjunction/doc-utils
15
15
  ## Dependencies
16
16
 
17
17
  This package depends on the following MemberJunction packages:
18
- - `@memberjunction/core`
19
- - `@memberjunction/core-entities`
20
- - `@memberjunction/global`
18
+ - `@memberjunction/core` - Core functionality and base classes
19
+ - `@memberjunction/core-entities` - Entity definitions
20
+ - `@memberjunction/global` - Global utilities and decorators
21
21
 
22
22
  External dependencies:
23
23
  - `jsdom` - For HTML parsing
@@ -25,11 +25,12 @@ External dependencies:
25
25
 
26
26
  ## Main Features
27
27
 
28
- - **Documentation Retrieval**: Dynamically fetch documentation from the MemberJunction documentation site
29
- - **HTML Parsing**: Extract relevant content from HTML documentation pages
30
- - **Caching Mechanism**: Improve performance by caching documentation content in memory
31
- - **Extended Entity Classes**: Access documentation for entities and their properties
28
+ - **Library Documentation Retrieval**: Dynamically fetch documentation for MemberJunction libraries and their items
29
+ - **HTML Content Parsing**: Extract relevant content from HTML documentation pages
30
+ - **Automatic URL Generation**: Constructs documentation URLs based on library and item metadata
31
+ - **Extended Entity Classes**: Provides extended functionality for Library and Library Item entities
32
32
  - **Singleton Pattern**: Easy access to documentation functionality throughout your application
33
+ - **Type-aware URL Routing**: Automatically routes to correct documentation sections based on item type (Class, Interface, Function, etc.)
33
34
 
34
35
  ## Usage
35
36
 
@@ -37,100 +38,152 @@ External dependencies:
37
38
 
38
39
  ```typescript
39
40
  import { DocumentationEngine } from '@memberjunction/doc-utils';
41
+ import { UserInfo } from '@memberjunction/core';
40
42
 
41
43
  // Get the singleton instance
42
- const docEngine = DocumentationEngine.getInstance();
43
-
44
- // Get documentation for a specific entity
45
- const entityDoc = await docEngine.getEntityDocumentation('User');
46
- console.log(entityDoc.description);
47
-
48
- // Get documentation for a specific entity field
49
- const fieldDoc = await docEngine.getEntityFieldDocumentation('User', 'Email');
50
- console.log(fieldDoc.description);
44
+ const docEngine = DocumentationEngine.Instance;
45
+
46
+ // Configure the engine (required before using)
47
+ const user = new UserInfo(); // Or get from your authentication context
48
+ await docEngine.Config(false, user);
49
+
50
+ // Access libraries and their documentation
51
+ const libraries = docEngine.Libraries;
52
+ console.log(`Found ${libraries.length} libraries`);
53
+
54
+ // Access specific library items
55
+ const coreLibrary = libraries.find(lib => lib.Name === '@memberjunction/core');
56
+ if (coreLibrary) {
57
+ console.log(`Library: ${coreLibrary.Name}`);
58
+ console.log(`Items: ${coreLibrary.Items.length}`);
59
+
60
+ // Access documentation for specific items
61
+ coreLibrary.Items.forEach(item => {
62
+ console.log(`${item.Type}: ${item.Name}`);
63
+ console.log(`URL: ${item.URL}`);
64
+ console.log(`Content Preview: ${item.HTMLContent.substring(0, 200)}...`);
65
+ });
66
+ }
51
67
  ```
52
68
 
53
- ### Working with Entity Documentation
69
+ ### Working with Library Items
54
70
 
55
71
  ```typescript
56
72
  import { DocumentationEngine } from '@memberjunction/doc-utils';
57
73
 
58
- async function displayEntityInfo(entityName: string) {
59
- const docEngine = DocumentationEngine.getInstance();
60
- const entityDoc = await docEngine.getEntityDocumentation(entityName);
61
-
62
- console.log(`Entity: ${entityName}`);
63
- console.log(`Description: ${entityDoc.description}`);
64
- console.log(`Base Table: ${entityDoc.baseTable}`);
65
- console.log(`Schema: ${entityDoc.schemaName}`);
66
-
67
- // Get all fields for the entity
68
- const fields = await docEngine.getEntityFieldsDocumentation(entityName);
69
-
70
- console.log('Fields:');
71
- fields.forEach(field => {
72
- console.log(`- ${field.name}: ${field.description}`);
73
- });
74
+ async function displayLibraryItemInfo(libraryName: string, itemName: string) {
75
+ const docEngine = DocumentationEngine.Instance;
76
+ await docEngine.Config();
77
+
78
+ // Find all library items
79
+ const libraryItems = docEngine.LibraryItems;
80
+
81
+ // Find specific item
82
+ const item = libraryItems.find(i =>
83
+ i.Library === libraryName && i.Name === itemName
84
+ );
85
+
86
+ if (item) {
87
+ console.log(`Item: ${item.Name}`);
88
+ console.log(`Type: ${item.Type}`);
89
+ console.log(`Library: ${item.Library}`);
90
+ console.log(`Documentation URL: ${item.URL}`);
91
+ console.log(`HTML Content Available: ${item.HTMLContent ? 'Yes' : 'No'}`);
92
+ }
74
93
  }
75
94
 
76
95
  // Example usage
77
- displayEntityInfo('User');
96
+ await displayLibraryItemInfo('@memberjunction/core', 'BaseEntity');
78
97
  ```
79
98
 
80
- ### Customizing Caching Behavior
99
+ ### Force Refresh Documentation
81
100
 
82
101
  ```typescript
83
102
  import { DocumentationEngine } from '@memberjunction/doc-utils';
84
103
 
85
- // Configure the documentation engine with custom settings
86
- DocumentationEngine.configure({
87
- cacheTimeoutMinutes: 60, // Cache documentation for 1 hour
88
- baseDocumentationUrl: 'https://custom-docs.memberjunction.com'
89
- });
90
-
91
- // Get the configured instance
92
- const docEngine = DocumentationEngine.getInstance();
104
+ // Force refresh to reload documentation from the database and website
105
+ const docEngine = DocumentationEngine.Instance;
106
+ await docEngine.Config(true); // true forces a refresh
93
107
  ```
94
108
 
95
109
  ## API Reference
96
110
 
97
111
  ### DocumentationEngine
98
112
 
99
- The main class that provides access to documentation functionality.
113
+ The main class that provides access to documentation functionality. Extends `BaseEngine` from `@memberjunction/core`.
114
+
115
+ #### Properties
116
+
117
+ - `Instance` (static): Returns the singleton instance of DocumentationEngine
118
+ - `Libraries`: Array of `LibraryEntityExtended` objects containing all loaded libraries
119
+ - `LibraryItems`: Array of `LibraryItemEntityExtended` objects containing all library items
100
120
 
101
121
  #### Methods
102
122
 
103
- - `getInstance()`: Returns the singleton instance of DocumentationEngine
104
- - `configure(options)`: Configure the documentation engine with custom settings
105
- - `getEntityDocumentation(entityName: string)`: Get documentation for a specific entity
106
- - `getEntityFieldDocumentation(entityName: string, fieldName: string)`: Get documentation for a specific entity field
107
- - `getEntityFieldsDocumentation(entityName: string)`: Get documentation for all fields of an entity
108
- - `clearCache()`: Clear the documentation cache
123
+ - `Config(forceRefresh?: boolean, contextUser?: UserInfo, provider?: IMetadataProvider): Promise<void>`
124
+ - Configures the documentation engine and loads metadata
125
+ - Parameters:
126
+ - `forceRefresh`: If true, forces reload of metadata from database
127
+ - `contextUser`: User context for server-side execution
128
+ - `provider`: Optional metadata provider
109
129
 
110
- ### EntityDocumentation
130
+ ### LibraryEntityExtended
111
131
 
112
- Class representing documentation for an entity.
132
+ Extended entity class for libraries with documentation capabilities.
113
133
 
114
134
  #### Properties
115
135
 
116
- - `name`: The name of the entity
117
- - `description`: The description of the entity
118
- - `baseTable`: The base table name in the database
119
- - `schemaName`: The database schema name
120
- - `fields`: Array of field documentation objects
136
+ - All properties from `LibraryEntity`
137
+ - `Items`: Array of `LibraryItemEntityExtended` objects belonging to this library
121
138
 
122
- ### EntityFieldDocumentation
139
+ ### LibraryItemEntityExtended
123
140
 
124
- Class representing documentation for an entity field.
141
+ Extended entity class for library items with documentation capabilities.
125
142
 
126
143
  #### Properties
127
144
 
128
- - `name`: The name of the field
129
- - `description`: The description of the field
130
- - `dataType`: The data type of the field
131
- - `length`: The length of the field (for string types)
132
- - `isPrimaryKey`: Whether the field is a primary key
133
- - `isNullable`: Whether the field can be null
145
+ - All properties from `LibraryItemEntity`
146
+ - `URL`: The generated documentation URL for this item
147
+ - `HTMLContent`: The parsed HTML content from the documentation
148
+ - `TypeURLSegment`: Returns the URL segment based on item type (classes, interfaces, functions, etc.)
149
+
150
+ #### Supported Item Types
151
+
152
+ - Class → `/classes/`
153
+ - Interface → `/interfaces/`
154
+ - Function → `/functions/`
155
+ - Module → `/modules/`
156
+ - Type → `/types/`
157
+ - Variable → `/variables/`
158
+
159
+ ## Integration with MemberJunction
160
+
161
+ This package integrates seamlessly with the MemberJunction ecosystem:
162
+
163
+ 1. **Entity System**: Uses MemberJunction's entity system for Library and Library Items metadata
164
+ 2. **Base Engine Pattern**: Extends BaseEngine for consistent configuration and loading patterns
165
+ 3. **Global Registration**: Uses `@RegisterClass` decorator for proper entity registration
166
+ 4. **User Context**: Supports MemberJunction's user context for server-side execution
167
+
168
+ ## Build and Development
169
+
170
+ ```bash
171
+ # Build the package
172
+ npm run build
173
+
174
+ # Run in development mode with hot reload
175
+ npm start
176
+
177
+ # Run tests (when implemented)
178
+ npm test
179
+ ```
180
+
181
+ ## Notes
182
+
183
+ - The documentation engine fetches content from https://memberjunction.github.io/MJ/
184
+ - Documentation is cached in memory after initial load for performance
185
+ - The engine automatically constructs URLs based on library names and item types
186
+ - Library names with special characters (@, ., /, \) are sanitized for URL compatibility
134
187
 
135
188
  ## License
136
189
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberjunction/doc-utils",
3
- "version": "2.43.0",
3
+ "version": "2.44.0",
4
4
  "description": "This library provides functionality for dynamically retreiving documentation from the official MemberJunction object model documentation site, parsing it, and caching elements in memory for performance. Use this whenever you need dynamic access to the MJ documentation to feed to AI models and for any other similar purpose.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,9 +19,9 @@
19
19
  "typescript": "^5.4.5"
20
20
  },
21
21
  "dependencies": {
22
- "@memberjunction/core": "2.43.0",
23
- "@memberjunction/core-entities": "2.43.0",
24
- "@memberjunction/global": "2.43.0",
22
+ "@memberjunction/core": "2.44.0",
23
+ "@memberjunction/core-entities": "2.44.0",
24
+ "@memberjunction/global": "2.44.0",
25
25
  "jsdom": "^24.1.0",
26
26
  "axios": "^1.6.7"
27
27
  }