@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 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
- * Walks entity relationship graphs to discover records for version labeling.
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 declare class DependencyGraphWalker {
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,OAAO,EAAE,YAAY,EAAuD,iBAAiB,EAAqB,QAAQ,EAAuB,MAAM,sBAAsB,CAAC;AAE9K,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AA6FtD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AACH,qBAAa,qBAAqB;IAC9B,+EAA+E;IAC/E,OAAO,CAAC,eAAe,CAA4C;IACnE,kEAAkE;IAClE,OAAO,CAAC,eAAe,CAAyC;IAEhE,gFAAgF;IAChF,OAAO,CAAC,SAAS,CAAC,CAAoB;IAEtC,4FAA4F;IAC5F,SAAS,KAAK,aAAa,IAAI,iBAAiB,CAE/C;IAMD;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