redis-graph-cache 1.0.2 → 1.0.3

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.
@@ -172,7 +172,22 @@ class HydrationEngine {
172
172
  if (context.excludeRelations?.includes(relationName)) {
173
173
  continue;
174
174
  }
175
- const promise = this.hydrateRelation(relationName, relationDef, normalizedEntity, hydratedEntity, context);
175
+ // Fork the visited-set per relation branch, synchronously, before any
176
+ // async work starts. `visitedEntities` tracks the *current path* for
177
+ // cycle detection (add on enter, delete on exit in `hydrateRecursive`).
178
+ // Sibling relations are hydrated concurrently (Promise.all below), so if
179
+ // they shared one Set, one branch's transient in-progress entries would
180
+ // leak into a sibling's view — making a shared entity referenced by both
181
+ // a parent and its child collection (a diamond, not a cycle) resolve to a
182
+ // `$ref` stub instead of the full object. A per-branch clone captures
183
+ // only the ancestor path, so real cycles down a branch are still caught
184
+ // while concurrent siblings stay isolated. This mirrors the per-item
185
+ // clone `batchHydrateEntities` already performs for `many` relations.
186
+ const branchContext = {
187
+ ...context,
188
+ visitedEntities: new Set(context.visitedEntities),
189
+ };
190
+ const promise = this.hydrateRelation(relationName, relationDef, normalizedEntity, hydratedEntity, branchContext);
176
191
  relationPromises.push(promise);
177
192
  }
178
193
  // Execute all relationship hydrations in parallel
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "redis-graph-cache",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A TypeScript-first Redis data layer with schema-driven normalization, relationship management, and graph-based hydration for high-performance Node.js applications.",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",