@memberjunction/doc-utils 3.4.0 → 4.1.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.
- package/README.md +315 -114
- package/dist/Engine.js +17 -24
- package/dist/Engine.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -17
- package/dist/index.js.map +1 -1
- package/package.json +24 -23
package/README.md
CHANGED
|
@@ -1,10 +1,171 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @memberjunction/doc-utils
|
|
2
2
|
|
|
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.
|
|
3
|
+
A TypeScript library for dynamically retrieving, parsing, and caching MemberJunction library documentation from the official documentation website. Designed to support AI models, code generation tools, and other documentation-driven features that need structured access to MJ library metadata.
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
The `@memberjunction/doc-utils` package provides
|
|
7
|
+
The `@memberjunction/doc-utils` package provides a singleton `DocumentationEngine` that loads library and library item metadata from the MemberJunction entity system, then fetches the corresponding HTML documentation pages from the official MJ documentation site ([https://memberjunction.github.io/MJ/](https://memberjunction.github.io/MJ/)). Parsed content is cached in memory for efficient repeated access.
|
|
8
|
+
|
|
9
|
+
This package is particularly useful for:
|
|
10
|
+
|
|
11
|
+
- Feeding structured library documentation to AI models for context-aware code generation
|
|
12
|
+
- Building developer tools that reference MJ API documentation
|
|
13
|
+
- Providing searchable documentation indexes for MJ packages and their exported items
|
|
14
|
+
|
|
15
|
+
## Architecture
|
|
16
|
+
|
|
17
|
+
```mermaid
|
|
18
|
+
graph TB
|
|
19
|
+
subgraph DocUtils["DocUtils Package"]
|
|
20
|
+
DE["DocumentationEngine<br/>(Singleton)"]
|
|
21
|
+
LEE["LibraryEntityExtended"]
|
|
22
|
+
LIEE["LibraryItemEntityExtended"]
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
subgraph MJCore["@memberjunction/core"]
|
|
26
|
+
BE["BaseEngine"]
|
|
27
|
+
BEnt["BaseEntity"]
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
subgraph CoreEntities["@memberjunction/core-entities"]
|
|
31
|
+
LE["LibraryEntity"]
|
|
32
|
+
LIE["LibraryItemEntity"]
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
subgraph External["External Services"]
|
|
36
|
+
DB[("MJ Database<br/>Libraries &<br/>Library Items")]
|
|
37
|
+
DOCS["MJ Docs Site<br/>memberjunction.github.io"]
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
DE -->|extends| BE
|
|
41
|
+
LEE -->|extends| LE
|
|
42
|
+
LIEE -->|extends| LIE
|
|
43
|
+
LE -->|extends| BEnt
|
|
44
|
+
LIE -->|extends| BEnt
|
|
45
|
+
|
|
46
|
+
DE -->|loads metadata| DB
|
|
47
|
+
DE -->|fetches HTML| DOCS
|
|
48
|
+
DE -->|manages| LEE
|
|
49
|
+
DE -->|manages| LIEE
|
|
50
|
+
LEE -->|contains| LIEE
|
|
51
|
+
|
|
52
|
+
style DE fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
53
|
+
style LEE fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
54
|
+
style LIEE fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
55
|
+
style BE fill:#7c5295,stroke:#563a6b,color:#fff
|
|
56
|
+
style BEnt fill:#7c5295,stroke:#563a6b,color:#fff
|
|
57
|
+
style LE fill:#7c5295,stroke:#563a6b,color:#fff
|
|
58
|
+
style LIE fill:#7c5295,stroke:#563a6b,color:#fff
|
|
59
|
+
style DB fill:#b8762f,stroke:#8a5722,color:#fff
|
|
60
|
+
style DOCS fill:#b8762f,stroke:#8a5722,color:#fff
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Data Flow
|
|
64
|
+
|
|
65
|
+
The engine follows a two-phase loading process: first it loads entity metadata from the database, then it fetches and parses HTML documentation for each library item.
|
|
66
|
+
|
|
67
|
+
```mermaid
|
|
68
|
+
sequenceDiagram
|
|
69
|
+
participant App as Application
|
|
70
|
+
participant DE as DocumentationEngine
|
|
71
|
+
participant DB as MJ Database
|
|
72
|
+
participant Site as Docs Website
|
|
73
|
+
|
|
74
|
+
App->>DE: Config(forceRefresh, contextUser)
|
|
75
|
+
DE->>DB: Load Libraries (entity metadata)
|
|
76
|
+
DB-->>DE: LibraryEntityExtended[]
|
|
77
|
+
DE->>DB: Load Library Items (entity metadata)
|
|
78
|
+
DB-->>DE: LibraryItemEntityExtended[]
|
|
79
|
+
|
|
80
|
+
Note over DE: AdditionalLoading phase
|
|
81
|
+
|
|
82
|
+
loop For each Library
|
|
83
|
+
loop For each Item in Library
|
|
84
|
+
DE->>DE: Build URL from library name + item type
|
|
85
|
+
DE->>Site: GET /{type}/{sanitized_name}.{ItemName}.html
|
|
86
|
+
Site-->>DE: HTML response
|
|
87
|
+
DE->>DE: Parse HTML via JSDOM (extract div.col-content)
|
|
88
|
+
DE->>DE: Cache HTMLContent and URL on item
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
DE-->>App: Config complete, data cached
|
|
93
|
+
App->>DE: Access Libraries / LibraryItems
|
|
94
|
+
DE-->>App: Cached entity data with HTML content
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Class Hierarchy
|
|
98
|
+
|
|
99
|
+
```mermaid
|
|
100
|
+
classDiagram
|
|
101
|
+
class BaseEngine {
|
|
102
|
+
<<abstract>>
|
|
103
|
+
+Load(configs, provider, forceRefresh, contextUser)
|
|
104
|
+
#AdditionalLoading(contextUser)*
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
class DocumentationEngine {
|
|
108
|
+
+Instance$ DocumentationEngine
|
|
109
|
+
+Libraries LibraryEntityExtended[]
|
|
110
|
+
+LibraryItems LibraryItemEntityExtended[]
|
|
111
|
+
+Config(forceRefresh, contextUser, provider)
|
|
112
|
+
#AdditionalLoading(contextUser)
|
|
113
|
+
#GetContent(url, rootSelector) string
|
|
114
|
+
#fetchDocumentation(url) string
|
|
115
|
+
#parseDocumentation(html, rootSelector) string
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
class BaseEntity {
|
|
119
|
+
<<abstract>>
|
|
120
|
+
+Get(fieldName)
|
|
121
|
+
+Set(fieldName, value)
|
|
122
|
+
+Save()
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
class LibraryEntity {
|
|
126
|
+
+ID string
|
|
127
|
+
+Name string
|
|
128
|
+
+Description string?
|
|
129
|
+
+Status "Active" | "Disabled" | "Pending"
|
|
130
|
+
+TypeDefinitions string?
|
|
131
|
+
+SampleCode string?
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
class LibraryEntityExtended {
|
|
135
|
+
+Items LibraryItemEntityExtended[]
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
class LibraryItemEntity {
|
|
139
|
+
+ID string
|
|
140
|
+
+Name string
|
|
141
|
+
+LibraryID string
|
|
142
|
+
+Type "Class"|"Function"|"Interface"|"Module"|"Type"|"Variable"
|
|
143
|
+
+Library string
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
class LibraryItemEntityExtended {
|
|
147
|
+
+URL string
|
|
148
|
+
+HTMLContent string
|
|
149
|
+
+TypeURLSegment string
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
BaseEngine <|-- DocumentationEngine
|
|
153
|
+
BaseEntity <|-- LibraryEntity
|
|
154
|
+
BaseEntity <|-- LibraryItemEntity
|
|
155
|
+
LibraryEntity <|-- LibraryEntityExtended
|
|
156
|
+
LibraryItemEntity <|-- LibraryItemEntityExtended
|
|
157
|
+
DocumentationEngine o-- LibraryEntityExtended
|
|
158
|
+
DocumentationEngine o-- LibraryItemEntityExtended
|
|
159
|
+
LibraryEntityExtended o-- LibraryItemEntityExtended
|
|
160
|
+
|
|
161
|
+
style DocumentationEngine fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
162
|
+
style LibraryEntityExtended fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
163
|
+
style LibraryItemEntityExtended fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
164
|
+
style BaseEngine fill:#7c5295,stroke:#563a6b,color:#fff
|
|
165
|
+
style BaseEntity fill:#7c5295,stroke:#563a6b,color:#fff
|
|
166
|
+
style LibraryEntity fill:#7c5295,stroke:#563a6b,color:#fff
|
|
167
|
+
style LibraryItemEntity fill:#7c5295,stroke:#563a6b,color:#fff
|
|
168
|
+
```
|
|
8
169
|
|
|
9
170
|
## Installation
|
|
10
171
|
|
|
@@ -14,27 +175,26 @@ npm install @memberjunction/doc-utils
|
|
|
14
175
|
|
|
15
176
|
## Dependencies
|
|
16
177
|
|
|
17
|
-
|
|
18
|
-
- `@memberjunction/core` - Core functionality and base classes
|
|
19
|
-
- `@memberjunction/core-entities` - Entity definitions
|
|
20
|
-
- `@memberjunction/global` - Global utilities and decorators
|
|
178
|
+
**MemberJunction packages:**
|
|
21
179
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
180
|
+
| Package | Purpose |
|
|
181
|
+
|---------|---------|
|
|
182
|
+
| `@memberjunction/core` | Base engine class, metadata provider, user context |
|
|
183
|
+
| `@memberjunction/core-entities` | `LibraryEntity` and `LibraryItemEntity` base classes |
|
|
184
|
+
| `@memberjunction/global` | `@RegisterClass` decorator for entity registration |
|
|
25
185
|
|
|
26
|
-
|
|
186
|
+
**External packages:**
|
|
27
187
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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.)
|
|
188
|
+
| Package | Purpose |
|
|
189
|
+
|---------|---------|
|
|
190
|
+
| `axios` | HTTP requests to the documentation website |
|
|
191
|
+
| `jsdom` | HTML parsing and DOM manipulation for content extraction |
|
|
34
192
|
|
|
35
193
|
## Usage
|
|
36
194
|
|
|
37
|
-
###
|
|
195
|
+
### Initializing the Engine
|
|
196
|
+
|
|
197
|
+
The `DocumentationEngine` uses the singleton pattern. Call `Config()` once to load metadata and documentation content before accessing data.
|
|
38
198
|
|
|
39
199
|
```typescript
|
|
40
200
|
import { DocumentationEngine } from '@memberjunction/doc-utils';
|
|
@@ -43,148 +203,189 @@ import { UserInfo } from '@memberjunction/core';
|
|
|
43
203
|
// Get the singleton instance
|
|
44
204
|
const docEngine = DocumentationEngine.Instance;
|
|
45
205
|
|
|
46
|
-
//
|
|
47
|
-
const
|
|
48
|
-
await docEngine.Config(false,
|
|
206
|
+
// Server-side: pass contextUser for proper data isolation
|
|
207
|
+
const contextUser: UserInfo = /* from your authentication context */;
|
|
208
|
+
await docEngine.Config(false, contextUser);
|
|
49
209
|
|
|
50
|
-
//
|
|
51
|
-
|
|
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
|
-
}
|
|
210
|
+
// Client-side: contextUser is optional
|
|
211
|
+
await docEngine.Config();
|
|
67
212
|
```
|
|
68
213
|
|
|
69
|
-
###
|
|
214
|
+
### Accessing Libraries and Items
|
|
215
|
+
|
|
216
|
+
After configuration, libraries and their items are available through cached properties.
|
|
70
217
|
|
|
71
218
|
```typescript
|
|
72
|
-
|
|
219
|
+
const docEngine = DocumentationEngine.Instance;
|
|
73
220
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
console.log(`
|
|
88
|
-
console.log(`
|
|
89
|
-
console.log(`Library: ${item.Library}`);
|
|
90
|
-
console.log(`Documentation URL: ${item.URL}`);
|
|
91
|
-
console.log(`HTML Content Available: ${item.HTMLContent ? 'Yes' : 'No'}`);
|
|
221
|
+
// Get all libraries
|
|
222
|
+
const libraries = docEngine.Libraries;
|
|
223
|
+
console.log(`Loaded ${libraries.length} libraries`);
|
|
224
|
+
|
|
225
|
+
// Find a specific library
|
|
226
|
+
const coreLib = libraries.find(lib => lib.Name === '@memberjunction/core');
|
|
227
|
+
if (coreLib) {
|
|
228
|
+
console.log(`${coreLib.Name} (${coreLib.Status})`);
|
|
229
|
+
console.log(`Items: ${coreLib.Items.length}`);
|
|
230
|
+
|
|
231
|
+
// Iterate through items in the library
|
|
232
|
+
for (const item of coreLib.Items) {
|
|
233
|
+
console.log(` ${item.Type}: ${item.Name}`);
|
|
234
|
+
console.log(` URL: ${item.URL}`);
|
|
235
|
+
console.log(` Content length: ${item.HTMLContent.length} chars`);
|
|
92
236
|
}
|
|
93
237
|
}
|
|
94
|
-
|
|
95
|
-
// Example usage
|
|
96
|
-
await displayLibraryItemInfo('@memberjunction/core', 'BaseEntity');
|
|
97
238
|
```
|
|
98
239
|
|
|
99
|
-
###
|
|
240
|
+
### Accessing All Library Items
|
|
241
|
+
|
|
242
|
+
The flat `LibraryItems` array provides access to all items across all libraries.
|
|
100
243
|
|
|
101
244
|
```typescript
|
|
102
|
-
|
|
245
|
+
const docEngine = DocumentationEngine.Instance;
|
|
246
|
+
|
|
247
|
+
// Get all library items regardless of library
|
|
248
|
+
const allItems = docEngine.LibraryItems;
|
|
249
|
+
|
|
250
|
+
// Filter by type
|
|
251
|
+
const allClasses = allItems.filter(item => item.Type === 'Class');
|
|
252
|
+
const allInterfaces = allItems.filter(item => item.Type === 'Interface');
|
|
253
|
+
|
|
254
|
+
// Find a specific item by name and library
|
|
255
|
+
const baseEntity = allItems.find(
|
|
256
|
+
item => item.Name === 'BaseEntity' && item.Library === '@memberjunction/core'
|
|
257
|
+
);
|
|
103
258
|
|
|
104
|
-
|
|
259
|
+
if (baseEntity) {
|
|
260
|
+
console.log(`Documentation URL: ${baseEntity.URL}`);
|
|
261
|
+
console.log(`HTML Content: ${baseEntity.HTMLContent}`);
|
|
262
|
+
}
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### Force Refreshing Documentation
|
|
266
|
+
|
|
267
|
+
Pass `true` to `Config()` to reload all metadata from the database and re-fetch documentation content.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
105
270
|
const docEngine = DocumentationEngine.Instance;
|
|
106
|
-
|
|
271
|
+
|
|
272
|
+
// Force a complete reload
|
|
273
|
+
await docEngine.Config(true);
|
|
107
274
|
```
|
|
108
275
|
|
|
109
276
|
## API Reference
|
|
110
277
|
|
|
111
278
|
### DocumentationEngine
|
|
112
279
|
|
|
113
|
-
The
|
|
280
|
+
The primary class providing access to MJ library documentation. Extends `BaseEngine` and uses the singleton pattern.
|
|
114
281
|
|
|
115
|
-
|
|
282
|
+
| Member | Type | Description |
|
|
283
|
+
|--------|------|-------------|
|
|
284
|
+
| `Instance` (static) | `DocumentationEngine` | Returns the singleton instance |
|
|
285
|
+
| `Libraries` | `LibraryEntityExtended[]` | All loaded libraries with their items |
|
|
286
|
+
| `LibraryItems` | `LibraryItemEntityExtended[]` | Flat list of all library items across all libraries |
|
|
287
|
+
| `Config(forceRefresh?, contextUser?, provider?)` | `Promise<void>` | Initializes the engine: loads metadata, fetches and parses documentation |
|
|
116
288
|
|
|
117
|
-
|
|
118
|
-
- `Libraries`: Array of `LibraryEntityExtended` objects containing all loaded libraries
|
|
119
|
-
- `LibraryItems`: Array of `LibraryItemEntityExtended` objects containing all library items
|
|
289
|
+
### LibraryEntityExtended
|
|
120
290
|
|
|
121
|
-
|
|
291
|
+
Extended entity class for libraries. Registered via `@RegisterClass(BaseEntity, "Libraries")`.
|
|
122
292
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
293
|
+
| Member | Type | Description |
|
|
294
|
+
|--------|------|-------------|
|
|
295
|
+
| `ID` | `string` | Unique identifier |
|
|
296
|
+
| `Name` | `string` | Library package name (e.g., `@memberjunction/core`) |
|
|
297
|
+
| `Description` | `string \| null` | Human-readable description |
|
|
298
|
+
| `Status` | `'Active' \| 'Disabled' \| 'Pending'` | Library availability status |
|
|
299
|
+
| `TypeDefinitions` | `string \| null` | Type/function definitions for reference by humans and AI |
|
|
300
|
+
| `SampleCode` | `string \| null` | Usage examples for the library |
|
|
301
|
+
| `Items` | `LibraryItemEntityExtended[]` | All items belonging to this library |
|
|
129
302
|
|
|
130
|
-
###
|
|
303
|
+
### LibraryItemEntityExtended
|
|
131
304
|
|
|
132
|
-
Extended entity class for
|
|
305
|
+
Extended entity class for individual library items (classes, interfaces, functions, etc.). Registered via `@RegisterClass(BaseEntity, "Library Items")`.
|
|
133
306
|
|
|
134
|
-
|
|
307
|
+
| Member | Type | Description |
|
|
308
|
+
|--------|------|-------------|
|
|
309
|
+
| `ID` | `string` | Unique identifier |
|
|
310
|
+
| `Name` | `string` | Item name (e.g., `BaseEntity`, `RunView`) |
|
|
311
|
+
| `LibraryID` | `string` | Foreign key to the parent library |
|
|
312
|
+
| `Library` | `string` | Denormalized library name from the view |
|
|
313
|
+
| `Type` | `'Class' \| 'Function' \| 'Interface' \| 'Module' \| 'Type' \| 'Variable'` | The kind of exported item |
|
|
314
|
+
| `URL` | `string` | Generated documentation URL for this item |
|
|
315
|
+
| `HTMLContent` | `string` | Parsed HTML content from the documentation page |
|
|
316
|
+
| `TypeURLSegment` | `string` (getter) | URL path segment derived from `Type` (e.g., `classes`, `interfaces`) |
|
|
135
317
|
|
|
136
|
-
|
|
137
|
-
- `Items`: Array of `LibraryItemEntityExtended` objects belonging to this library
|
|
318
|
+
### URL Generation
|
|
138
319
|
|
|
139
|
-
|
|
320
|
+
Documentation URLs are constructed automatically using the pattern:
|
|
140
321
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
322
|
+
```
|
|
323
|
+
https://memberjunction.github.io/MJ/{typeSegment}/{sanitizedLibraryName}.{ItemName}.html
|
|
324
|
+
```
|
|
144
325
|
|
|
145
|
-
|
|
146
|
-
- `
|
|
147
|
-
- `
|
|
148
|
-
- `
|
|
326
|
+
Where:
|
|
327
|
+
- `{typeSegment}` is the pluralized, lowercase item type (`classes`, `interfaces`, `functions`, `modules`, `types`, `variables`)
|
|
328
|
+
- `{sanitizedLibraryName}` is the library name with `@`, `.`, `/`, and `\` characters replaced by `_`
|
|
329
|
+
- `{ItemName}` is the exact name of the exported item
|
|
149
330
|
|
|
150
|
-
|
|
331
|
+
For example, `BaseEntity` (a Class) in `@memberjunction/core` resolves to:
|
|
332
|
+
```
|
|
333
|
+
https://memberjunction.github.io/MJ/classes/_memberjunction_core.BaseEntity.html
|
|
334
|
+
```
|
|
151
335
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
336
|
+
## URL Routing by Item Type
|
|
337
|
+
|
|
338
|
+
```mermaid
|
|
339
|
+
graph LR
|
|
340
|
+
Item["Library Item"]
|
|
341
|
+
|
|
342
|
+
Item -->|Class| C["/classes/"]
|
|
343
|
+
Item -->|Interface| I["/interfaces/"]
|
|
344
|
+
Item -->|Function| F["/functions/"]
|
|
345
|
+
Item -->|Module| M["/modules/"]
|
|
346
|
+
Item -->|Type| T["/types/"]
|
|
347
|
+
Item -->|Variable| V["/variables/"]
|
|
348
|
+
|
|
349
|
+
style Item fill:#2d6a9f,stroke:#1a4971,color:#fff
|
|
350
|
+
style C fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
351
|
+
style I fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
352
|
+
style F fill:#2d8659,stroke:#1a5c3a,color:#fff
|
|
353
|
+
style M fill:#b8762f,stroke:#8a5722,color:#fff
|
|
354
|
+
style T fill:#b8762f,stroke:#8a5722,color:#fff
|
|
355
|
+
style V fill:#b8762f,stroke:#8a5722,color:#fff
|
|
356
|
+
```
|
|
158
357
|
|
|
159
358
|
## Integration with MemberJunction
|
|
160
359
|
|
|
161
|
-
This package integrates
|
|
360
|
+
This package integrates with the broader MemberJunction ecosystem through several mechanisms:
|
|
162
361
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
362
|
+
- **Entity System**: Uses `@RegisterClass` to register `LibraryEntityExtended` and `LibraryItemEntityExtended` as entity subclasses, ensuring the MJ class factory returns the extended types when loading Libraries and Library Items.
|
|
363
|
+
- **BaseEngine Pattern**: Extends `BaseEngine` with the `Config()` / `AdditionalLoading()` lifecycle, allowing consistent initialization and caching across all MJ engine classes.
|
|
364
|
+
- **User Context**: Supports `contextUser` for proper data isolation and security when running on the server side.
|
|
365
|
+
- **Metadata Provider**: Accepts an optional `IMetadataProvider` for environments with custom metadata access patterns.
|
|
167
366
|
|
|
168
|
-
## Build
|
|
367
|
+
## Build
|
|
169
368
|
|
|
170
369
|
```bash
|
|
171
370
|
# Build the package
|
|
371
|
+
cd packages/DocUtils
|
|
172
372
|
npm run build
|
|
173
373
|
|
|
174
|
-
#
|
|
374
|
+
# Development mode with file watching
|
|
175
375
|
npm start
|
|
176
|
-
|
|
177
|
-
# Run tests (when implemented)
|
|
178
|
-
npm test
|
|
179
376
|
```
|
|
180
377
|
|
|
181
|
-
##
|
|
378
|
+
## Source Files
|
|
182
379
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
380
|
+
| File | Description |
|
|
381
|
+
|------|-------------|
|
|
382
|
+
| `src/index.ts` | Public API surface -- re-exports from `Engine.ts` |
|
|
383
|
+
| `src/Engine.ts` | Core implementation: `DocumentationEngine`, `LibraryEntityExtended`, `LibraryItemEntityExtended` |
|
|
187
384
|
|
|
188
|
-
##
|
|
385
|
+
## Notes
|
|
189
386
|
|
|
190
|
-
|
|
387
|
+
- Documentation is fetched from [https://memberjunction.github.io/MJ/](https://memberjunction.github.io/MJ/) using `axios` HTTP GET requests.
|
|
388
|
+
- HTML content is parsed with `jsdom`, extracting the inner HTML of the `div.col-content` element from each page.
|
|
389
|
+
- All fetched content is cached in memory after the initial `Config()` call. Subsequent calls to `Config()` without `forceRefresh=true` return immediately.
|
|
390
|
+
- Library names containing special characters (`@`, `.`, `/`, `\`) are sanitized by replacing them with underscores for URL compatibility.
|
|
391
|
+
- If a documentation page cannot be fetched (network error, 404, etc.), the `HTMLContent` for that item is set to an error or placeholder string rather than throwing an exception.
|
package/dist/Engine.js
CHANGED
|
@@ -1,25 +1,19 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
const axios_1 = __importDefault(require("axios"));
|
|
14
|
-
const jsdom_1 = require("jsdom");
|
|
15
|
-
const core_1 = require("@memberjunction/core");
|
|
16
|
-
const core_entities_1 = require("@memberjunction/core-entities");
|
|
17
|
-
const global_1 = require("@memberjunction/global");
|
|
7
|
+
import axios from 'axios';
|
|
8
|
+
import { JSDOM } from 'jsdom';
|
|
9
|
+
import { BaseEngine, LogError, BaseEntity } from "@memberjunction/core";
|
|
10
|
+
import { LibraryEntity, LibraryItemEntity } from "@memberjunction/core-entities";
|
|
11
|
+
import { RegisterClass } from '@memberjunction/global';
|
|
18
12
|
/**
|
|
19
13
|
* Represents a single item within a library/package that is used to provide documentation for the MemberJunction system. For example a library would be something like
|
|
20
14
|
* @memberjunction/core and an item within that library might be the BaseEntity or BaseEngine class.
|
|
21
15
|
*/
|
|
22
|
-
let LibraryItemEntityExtended = class LibraryItemEntityExtended extends
|
|
16
|
+
let LibraryItemEntityExtended = class LibraryItemEntityExtended extends LibraryItemEntity {
|
|
23
17
|
get TypeURLSegment() {
|
|
24
18
|
switch (this.Type) {
|
|
25
19
|
case 'Class':
|
|
@@ -39,11 +33,11 @@ let LibraryItemEntityExtended = class LibraryItemEntityExtended extends core_ent
|
|
|
39
33
|
}
|
|
40
34
|
}
|
|
41
35
|
};
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
(0, global_1.RegisterClass)(core_1.BaseEntity, "Library Items")
|
|
36
|
+
LibraryItemEntityExtended = __decorate([
|
|
37
|
+
RegisterClass(BaseEntity, "Library Items")
|
|
45
38
|
], LibraryItemEntityExtended);
|
|
46
|
-
|
|
39
|
+
export { LibraryItemEntityExtended };
|
|
40
|
+
let LibraryEntityExtended = class LibraryEntityExtended extends LibraryEntity {
|
|
47
41
|
constructor() {
|
|
48
42
|
super(...arguments);
|
|
49
43
|
this._items = [];
|
|
@@ -52,14 +46,14 @@ let LibraryEntityExtended = class LibraryEntityExtended extends core_entities_1.
|
|
|
52
46
|
return this._items;
|
|
53
47
|
}
|
|
54
48
|
};
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
(0, global_1.RegisterClass)(core_1.BaseEntity, "Libraries")
|
|
49
|
+
LibraryEntityExtended = __decorate([
|
|
50
|
+
RegisterClass(BaseEntity, "Libraries")
|
|
58
51
|
], LibraryEntityExtended);
|
|
52
|
+
export { LibraryEntityExtended };
|
|
59
53
|
/**
|
|
60
54
|
* Provides utility functionality for documentation of the MemberJunction system using external website content from the MemberJunction project.
|
|
61
55
|
*/
|
|
62
|
-
class DocumentationEngine extends
|
|
56
|
+
export class DocumentationEngine extends BaseEngine {
|
|
63
57
|
constructor() {
|
|
64
58
|
super(...arguments);
|
|
65
59
|
// internal instance properties used for the singleton pattern
|
|
@@ -110,7 +104,7 @@ class DocumentationEngine extends core_1.BaseEngine {
|
|
|
110
104
|
}
|
|
111
105
|
async fetchDocumentation(url) {
|
|
112
106
|
try {
|
|
113
|
-
const response = await
|
|
107
|
+
const response = await axios.get(url);
|
|
114
108
|
if (response.status === 200) {
|
|
115
109
|
return response.data;
|
|
116
110
|
}
|
|
@@ -119,12 +113,12 @@ class DocumentationEngine extends core_1.BaseEngine {
|
|
|
119
113
|
}
|
|
120
114
|
}
|
|
121
115
|
catch (e) {
|
|
122
|
-
|
|
116
|
+
LogError(e);
|
|
123
117
|
return "Error fetching content";
|
|
124
118
|
}
|
|
125
119
|
}
|
|
126
120
|
parseDocumentation(html, rootSelector) {
|
|
127
|
-
const dom = new
|
|
121
|
+
const dom = new JSDOM(html);
|
|
128
122
|
const document = dom.window.document;
|
|
129
123
|
const content = document.querySelector('div.col-content')?.innerHTML;
|
|
130
124
|
return content || 'No relevant content found';
|
|
@@ -142,5 +136,4 @@ class DocumentationEngine extends core_1.BaseEngine {
|
|
|
142
136
|
return this._LibraryItems;
|
|
143
137
|
}
|
|
144
138
|
}
|
|
145
|
-
exports.DocumentationEngine = DocumentationEngine;
|
|
146
139
|
//# sourceMappingURL=Engine.js.map
|
package/dist/Engine.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"Engine.js","sourceRoot":"","sources":["../src/Engine.ts"],"names":[],"mappings":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
|
|
1
|
+
export * from './Engine.js';
|
|
2
2
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
//PUBLIC API SURFACE AREA
|
|
3
|
-
|
|
4
|
-
if (k2 === undefined) k2 = k;
|
|
5
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
-
}
|
|
9
|
-
Object.defineProperty(o, k2, desc);
|
|
10
|
-
}) : (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
o[k2] = m[k];
|
|
13
|
-
}));
|
|
14
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
15
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
16
|
-
};
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
__exportStar(require("./Engine"), exports);
|
|
2
|
+
export * from './Engine.js';
|
|
19
3
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,yBAAyB;AAEzB,cAAc,UAAU,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberjunction/doc-utils",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "4.1.0",
|
|
4
5
|
"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
6
|
"main": "dist/index.js",
|
|
6
7
|
"types": "dist/index.d.ts",
|
|
@@ -9,43 +10,43 @@
|
|
|
9
10
|
],
|
|
10
11
|
"scripts": {
|
|
11
12
|
"start": "ts-node-dev src/index.ts",
|
|
12
|
-
"build": "tsc",
|
|
13
|
+
"build": "tsc && tsc-alias -f",
|
|
13
14
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
15
|
},
|
|
15
16
|
"author": "MemberJunction.com",
|
|
16
17
|
"license": "ISC",
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"ts-node-dev": "^2.0.0",
|
|
19
|
-
"typescript": "^5.
|
|
20
|
+
"typescript": "^5.9.3"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"@asamuzakjp/css-color": "^
|
|
23
|
-
"@memberjunction/core": "
|
|
24
|
-
"@memberjunction/core-entities": "
|
|
25
|
-
"@memberjunction/global": "
|
|
26
|
-
"axios": "^1.
|
|
27
|
-
"cssstyle": "^
|
|
28
|
-
"data-urls": "^
|
|
29
|
-
"decimal.js": "^10.
|
|
30
|
-
"form-data": "^4.0.
|
|
23
|
+
"@asamuzakjp/css-color": "^4.1.2",
|
|
24
|
+
"@memberjunction/core": "4.1.0",
|
|
25
|
+
"@memberjunction/core-entities": "4.1.0",
|
|
26
|
+
"@memberjunction/global": "4.1.0",
|
|
27
|
+
"axios": "^1.13.4",
|
|
28
|
+
"cssstyle": "^6.0.1",
|
|
29
|
+
"data-urls": "^7.0.0",
|
|
30
|
+
"decimal.js": "^10.6.0",
|
|
31
|
+
"form-data": "^4.0.5",
|
|
31
32
|
"html-encoding-sniffer": "^6.0.0",
|
|
32
33
|
"http-proxy-agent": "^7.0.2",
|
|
33
|
-
"https-proxy-agent": "^7.0.
|
|
34
|
+
"https-proxy-agent": "^7.0.6",
|
|
34
35
|
"is-potential-custom-element-name": "^1.0.1",
|
|
35
|
-
"jsdom": "^
|
|
36
|
-
"nwsapi": "^2.2.
|
|
37
|
-
"parse5": "^
|
|
38
|
-
"psl": "^1.
|
|
39
|
-
"rrweb-cssom": "^0.
|
|
36
|
+
"jsdom": "^28.0.0",
|
|
37
|
+
"nwsapi": "^2.2.23",
|
|
38
|
+
"parse5": "^8.0.0",
|
|
39
|
+
"psl": "^1.15.0",
|
|
40
|
+
"rrweb-cssom": "^0.8.0",
|
|
40
41
|
"saxes": "^6.0.0",
|
|
41
42
|
"symbol-tree": "^3.2.4",
|
|
42
|
-
"tough-cookie": "^
|
|
43
|
+
"tough-cookie": "^6.0.0",
|
|
43
44
|
"w3c-xmlserializer": "^5.0.0",
|
|
44
|
-
"webidl-conversions": "^
|
|
45
|
+
"webidl-conversions": "^8.0.1",
|
|
45
46
|
"whatwg-encoding": "^3.1.1",
|
|
46
|
-
"whatwg-mimetype": "^
|
|
47
|
-
"whatwg-url": "^
|
|
48
|
-
"ws": "^8.
|
|
47
|
+
"whatwg-mimetype": "^5.0.0",
|
|
48
|
+
"whatwg-url": "^16.0.0",
|
|
49
|
+
"ws": "^8.19.0",
|
|
49
50
|
"xml-name-validator": "^5.0.0"
|
|
50
51
|
},
|
|
51
52
|
"repository": {
|