@memberjunction/version-history 6.2.0-edge.0 → 6.2.0-edge.2
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 +3 -0
- package/dist/DependencyGraphWalker.d.ts +3 -166
- package/dist/DependencyGraphWalker.d.ts.map +1 -1
- package/dist/DependencyGraphWalker.js +3 -503
- package/dist/DependencyGraphWalker.js.map +1 -1
- package/dist/DiffEngine.js +17 -17
- package/dist/LabelManager.js +8 -8
- package/dist/RestoreEngine.d.ts +3 -2
- package/dist/RestoreEngine.d.ts.map +1 -1
- package/dist/RestoreEngine.js +16 -52
- package/dist/RestoreEngine.js.map +1 -1
- package/dist/SnapshotBuilder.d.ts +1 -1
- package/dist/SnapshotBuilder.js +7 -7
- package/dist/VersionHistoryEngine.d.ts +7 -6
- package/dist/VersionHistoryEngine.d.ts.map +1 -1
- package/dist/VersionHistoryEngine.js +18 -18
- package/dist/VersionHistoryEngine.js.map +1 -1
- package/dist/constants.d.ts +5 -48
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +16 -73
- package/dist/constants.js.map +1 -1
- package/dist/types.d.ts +2 -35
- package/dist/types.d.ts.map +1 -1
- package/package.json +5 -4
package/README.md
CHANGED
|
@@ -6,6 +6,9 @@ Version labeling, snapshot capture, diff, and restore for MemberJunction records
|
|
|
6
6
|
|
|
7
7
|
The `@memberjunction/version-history` package enables developers to create named version labels that capture record state at specific points in time, compare changes between labels, and restore records to previous states while respecting entity dependency ordering.
|
|
8
8
|
|
|
9
|
+
> [!NOTE]
|
|
10
|
+
> The core record dependency traversal, topological sorting, and link resolution engine (`DependencyGraphWalker`, `SortByEntityDependencyOrder`, `SortNodesTopologically`) has been extracted into [`@memberjunction/record-graph`](../RecordGraph/README.md) so it can be shared across Version History, Record Cloning, and Metadata Sync. Version History re-exports these symbols for backward compatibility.
|
|
11
|
+
|
|
9
12
|
```mermaid
|
|
10
13
|
graph TD
|
|
11
14
|
A["VersionHistoryEngine<br/>(Facade)"] --> B["LabelManager"]
|
|
@@ -1,169 +1,6 @@
|
|
|
1
|
-
import { CompositeKey, IMetadataProvider, UserInfo } from '@memberjunction/core';
|
|
2
|
-
import { DependencyNode, WalkOptions } from './types.js';
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* ## Two-direction traversal
|
|
7
|
-
*
|
|
8
|
-
* **Reverse**: Uses the entity's `RelatedEntities` (EntityRelationship metadata)
|
|
9
|
-
* to find child records. This is curated by CodeGen and admins — only explicitly
|
|
10
|
-
* registered One-To-Many relationships are walked.
|
|
11
|
-
*
|
|
12
|
-
* **Forward**: Scans the current entity's own FK fields to find records it
|
|
13
|
-
* references (e.g., AI Agent Prompt → AI Prompt via PromptID). Skips
|
|
14
|
-
* system/infrastructure fields (UserID, CreatedBy, etc.).
|
|
15
|
-
*
|
|
16
|
-
* ## Discovery mode — prevents explosion from forward references
|
|
17
|
-
*
|
|
18
|
-
* Records found via **reverse walk** are "owned children" and get full treatment
|
|
19
|
-
* (both reverse + forward walks). Records found via **forward walk** are
|
|
20
|
-
* "referenced records" and only get forward-only treatment (their own FK refs
|
|
21
|
-
* are followed, but their EntityRelationship children are NOT discovered).
|
|
22
|
-
*
|
|
23
|
-
* This prevents the classic explosion pattern:
|
|
24
|
-
* ```
|
|
25
|
-
* Agent → AgentPrompt → Prompt → [reverse to ALL PromptModels] → Model
|
|
26
|
-
* → [reverse to ALL AgentModels across ALL agents] → explosion!
|
|
27
|
-
* ```
|
|
28
|
-
*
|
|
29
|
-
* With discovery mode:
|
|
30
|
-
* ```
|
|
31
|
-
* Agent → AgentPrompt(reverse,full) → Prompt(forward,forward-only)
|
|
32
|
-
* → Model(forward,forward-only) → STOP (no reverse walk on Model)
|
|
33
|
-
* ```
|
|
34
|
-
*
|
|
35
|
-
* ## Ancestor stack — prevents backtracking
|
|
36
|
-
*
|
|
37
|
-
* A set of entity names on the current path from root to the current node is
|
|
38
|
-
* maintained. When evaluating any relationship, if the target entity type is
|
|
39
|
-
* already on the ancestor stack, it is skipped. This is a secondary safety net
|
|
40
|
-
* that prevents cycles even within full-mode walks.
|
|
41
|
-
*
|
|
42
|
-
* ## Filters
|
|
43
|
-
*
|
|
44
|
-
* - Only walks entities with `TrackRecordChanges === true`
|
|
45
|
-
* - Skips system FK fields via regex patterns (UserID, CreatedBy, etc.)
|
|
46
|
-
* - Respects `ExcludeEntities` and `EntityFilter` options
|
|
47
|
-
* - Uses a global `visited` set for record-level cycle detection
|
|
2
|
+
* NOTE: DependencyGraphWalker has moved to @memberjunction/record-graph.
|
|
3
|
+
* Re-exported here for backward compatibility.
|
|
48
4
|
*/
|
|
49
|
-
export
|
|
50
|
-
/** Cache: entityID → reverse relationships from EntityRelationship metadata */
|
|
51
|
-
private reverseRelCache;
|
|
52
|
-
/** Cache: entityID → forward FK references from field metadata */
|
|
53
|
-
private forwardRefCache;
|
|
54
|
-
/** Optional provider override; falls back to Metadata.Provider when not set. */
|
|
55
|
-
private _provider?;
|
|
56
|
-
/** Returns the active provider — explicit override if set, otherwise the global default. */
|
|
57
|
-
protected get ProviderToUse(): IMetadataProvider;
|
|
58
|
-
/**
|
|
59
|
-
* Walk from a root record through its relationships, building a tree of
|
|
60
|
-
* all records that should be included in a version label.
|
|
61
|
-
*
|
|
62
|
-
* @param entityName - The starting entity name
|
|
63
|
-
* @param recordKey - The starting record's primary key
|
|
64
|
-
* @param options - Controls depth, filtering, etc.
|
|
65
|
-
* @param contextUser - Server-side user context
|
|
66
|
-
* @returns The root DependencyNode with all descendants populated
|
|
67
|
-
*/
|
|
68
|
-
WalkDependents(entityName: string, recordKey: CompositeKey, options: WalkOptions, contextUser: UserInfo): Promise<DependencyNode>;
|
|
69
|
-
/**
|
|
70
|
-
* Flatten a dependency tree into a topologically sorted list.
|
|
71
|
-
* Parents appear before their children, ensuring safe restore ordering.
|
|
72
|
-
*/
|
|
73
|
-
FlattenTopological(root: DependencyNode): DependencyNode[];
|
|
74
|
-
/**
|
|
75
|
-
* Recursively discover and attach child nodes for a given parent node.
|
|
76
|
-
*
|
|
77
|
-
* The `discoveryMode` controls which directions are walked:
|
|
78
|
-
* - `'full'`: both reverse (EntityRelationship) and forward (FK refs)
|
|
79
|
-
* - `'forward-only'`: only forward FK refs — no reverse children discovered
|
|
80
|
-
*
|
|
81
|
-
* Records found via reverse walk are recursed with `'full'` mode.
|
|
82
|
-
* Records found via forward walk are recursed with `'forward-only'` mode.
|
|
83
|
-
*/
|
|
84
|
-
private walkChildren;
|
|
85
|
-
/**
|
|
86
|
-
* Walk reverse relationships: for each EntityRelationship on the parent
|
|
87
|
-
* entity, load matching child records and recurse into them.
|
|
88
|
-
*
|
|
89
|
-
* Skips any child entity type that is already on the ancestor stack,
|
|
90
|
-
* preventing backtracking (e.g., from AI Prompt back to AI Agent Prompts).
|
|
91
|
-
*
|
|
92
|
-
* Children found via reverse walk are recursed with 'full' discovery mode,
|
|
93
|
-
* since they are "owned children" that may have their own children.
|
|
94
|
-
*/
|
|
95
|
-
private walkReverseRelationships;
|
|
96
|
-
/**
|
|
97
|
-
* Walk forward FK references: for each FK field on the parent entity that
|
|
98
|
-
* points to another tracked entity, load the referenced record and recurse.
|
|
99
|
-
*
|
|
100
|
-
* Skips system/infrastructure FKs (UserID, CreatedBy, etc.) and any target
|
|
101
|
-
* entity type already on the ancestor stack.
|
|
102
|
-
*
|
|
103
|
-
* Targets found via forward walk are recursed with 'forward-only' discovery
|
|
104
|
-
* mode — they won't discover their own reverse children, preventing graph
|
|
105
|
-
* explosion from "hub" entities like AI Models.
|
|
106
|
-
*/
|
|
107
|
-
private walkForwardReferences;
|
|
108
|
-
/**
|
|
109
|
-
* Discover reverse relationships for an entity using EntityRelationship
|
|
110
|
-
* metadata. Only includes One-To-Many relationships to entities that have
|
|
111
|
-
* TrackRecordChanges enabled.
|
|
112
|
-
*
|
|
113
|
-
* Uses EntityRelationship (already loaded in memory on EntityInfo) rather
|
|
114
|
-
* than scanning all entities' FK fields. This means only relationships
|
|
115
|
-
* that CodeGen or admins have explicitly registered are walked.
|
|
116
|
-
*/
|
|
117
|
-
private discoverReverseRelationships;
|
|
118
|
-
/**
|
|
119
|
-
* Discover forward FK references on an entity — fields that point TO other
|
|
120
|
-
* entities. Only includes references to entities with TrackRecordChanges
|
|
121
|
-
* enabled, and skips system/infrastructure FK fields.
|
|
122
|
-
*/
|
|
123
|
-
private discoverForwardReferences;
|
|
124
|
-
/**
|
|
125
|
-
* Load child records for a reverse relationship.
|
|
126
|
-
* Queries the child entity where the join field matches the parent's key value.
|
|
127
|
-
*/
|
|
128
|
-
private loadChildRecords;
|
|
129
|
-
/**
|
|
130
|
-
* Load a single record's data by primary key.
|
|
131
|
-
*/
|
|
132
|
-
private loadRecordData;
|
|
133
|
-
/**
|
|
134
|
-
* Build a DependencyNode from record data, register it in the visited set,
|
|
135
|
-
* and attach it as a child of the parent. Returns null if already visited.
|
|
136
|
-
*/
|
|
137
|
-
private registerNode;
|
|
138
|
-
/** Create an empty stats accumulator. */
|
|
139
|
-
private createEmptyStats;
|
|
140
|
-
/** Increment the per-entity record counter. */
|
|
141
|
-
private incrementEntityCount;
|
|
142
|
-
/**
|
|
143
|
-
* Log a detailed summary of the walk: total records, per-entity counts,
|
|
144
|
-
* skips, and suppression stats.
|
|
145
|
-
*/
|
|
146
|
-
private logWalkSummary;
|
|
147
|
-
/** Build a unique key for the visited set: "EntityName::recordID" */
|
|
148
|
-
private visitKey;
|
|
149
|
-
/**
|
|
150
|
-
* Determine the parent key field from an EntityRelationship record.
|
|
151
|
-
* Uses EntityKeyField if specified, otherwise falls back to the first PK.
|
|
152
|
-
*/
|
|
153
|
-
private resolveParentKeyFieldFromRelationship;
|
|
154
|
-
/**
|
|
155
|
-
* Determine the target key field from a FK field definition.
|
|
156
|
-
* Uses RelatedEntityFieldName if specified, otherwise falls back to the
|
|
157
|
-
* target entity's first PK.
|
|
158
|
-
*/
|
|
159
|
-
private resolveParentKeyFieldFromFK;
|
|
160
|
-
/** Check if a field name matches a system/infrastructure FK pattern. */
|
|
161
|
-
private isSystemFKField;
|
|
162
|
-
/** Check if an entity should be skipped based on filter options. */
|
|
163
|
-
private shouldSkipEntity;
|
|
164
|
-
/** Check if an entity has a soft delete field. */
|
|
165
|
-
private entityHasSoftDelete;
|
|
166
|
-
/** Apply defaults to walk options. */
|
|
167
|
-
private resolveDefaults;
|
|
168
|
-
}
|
|
5
|
+
export { DependencyGraphWalker } from '@memberjunction/record-graph';
|
|
169
6
|
//# sourceMappingURL=DependencyGraphWalker.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyGraphWalker.d.ts","sourceRoot":"","sources":["../src/DependencyGraphWalker.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"DependencyGraphWalker.d.ts","sourceRoot":"","sources":["../src/DependencyGraphWalker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC"}
|