@utaba/deep-memory-storage-cosmosdb 0.17.0 → 0.18.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/dist/index.d.cts CHANGED
@@ -181,11 +181,11 @@ declare class CosmosDbProvider implements StorageProvider, GraphTraversalProvide
181
181
  *
182
182
  * The server-side step direction is fixed to `'both'` (catches every edge
183
183
  * in either direction). The directional + bidirectional filter is applied
184
- * client-side per hop — i.e. `direction: 'outbound'` includes inbound edges
184
+ * client-side per hop — i.e. `direction: 'out'` includes inbound edges
185
185
  * where `bidirectional` is true. The CosmosDB Gremlin compiler does not
186
186
  * natively express the `union(outE, inE.has(bidirectional))` shape that
187
187
  * would push this filter server-side, so it stays client-side; the
188
- * observable contract (which edges count toward "outbound" given
188
+ * observable contract (which edges count toward `'out'` given
189
189
  * bidirectionality) is preserved.
190
190
  *
191
191
  * Round-trips per call: `options.depth` (one per layer). The previous BFS
package/dist/index.d.ts CHANGED
@@ -181,11 +181,11 @@ declare class CosmosDbProvider implements StorageProvider, GraphTraversalProvide
181
181
  *
182
182
  * The server-side step direction is fixed to `'both'` (catches every edge
183
183
  * in either direction). The directional + bidirectional filter is applied
184
- * client-side per hop — i.e. `direction: 'outbound'` includes inbound edges
184
+ * client-side per hop — i.e. `direction: 'out'` includes inbound edges
185
185
  * where `bidirectional` is true. The CosmosDB Gremlin compiler does not
186
186
  * natively express the `union(outE, inE.has(bidirectional))` shape that
187
187
  * would push this filter server-side, so it stays client-side; the
188
- * observable contract (which edges count toward "outbound" given
188
+ * observable contract (which edges count toward `'out'` given
189
189
  * bidirectionality) is preserved.
190
190
  *
191
191
  * Round-trips per call: `options.depth` (one per layer). The previous BFS
package/dist/index.js CHANGED
@@ -1227,10 +1227,10 @@ async function getEntityRelationships(conn, repositoryId, entityId, options) {
1227
1227
  };
1228
1228
  let edgeTraversal;
1229
1229
  switch (direction) {
1230
- case "outbound":
1230
+ case "out":
1231
1231
  edgeTraversal = "g.V().has('repositoryId', rid).hasId(eid).has('entityType').outE()";
1232
1232
  break;
1233
- case "inbound":
1233
+ case "in":
1234
1234
  edgeTraversal = "g.V().has('repositoryId', rid).hasId(eid).has('entityType').inE()";
1235
1235
  break;
1236
1236
  case "both":
@@ -1249,9 +1249,9 @@ async function getEntityRelationships(conn, repositoryId, entityId, options) {
1249
1249
  typeFilter = `.hasLabel(${typeParams.join(", ")})`;
1250
1250
  }
1251
1251
  let unionQuery = null;
1252
- if (direction === "outbound") {
1252
+ if (direction === "out") {
1253
1253
  unionQuery = `g.V().has('repositoryId', rid).hasId(eid).has('entityType').union(outE()${typeFilter}, inE()${typeFilter}.has('bidirectional', true))`;
1254
- } else if (direction === "inbound") {
1254
+ } else if (direction === "in") {
1255
1255
  unionQuery = `g.V().has('repositoryId', rid).hasId(eid).has('entityType').union(inE()${typeFilter}, outE()${typeFilter}.has('bidirectional', true))`;
1256
1256
  }
1257
1257
  const baseQuery = unionQuery ?? `${edgeTraversal}${typeFilter}`;
@@ -2340,11 +2340,11 @@ Verify the ARM/Bicep template that provisioned the container.`
2340
2340
  *
2341
2341
  * The server-side step direction is fixed to `'both'` (catches every edge
2342
2342
  * in either direction). The directional + bidirectional filter is applied
2343
- * client-side per hop — i.e. `direction: 'outbound'` includes inbound edges
2343
+ * client-side per hop — i.e. `direction: 'out'` includes inbound edges
2344
2344
  * where `bidirectional` is true. The CosmosDB Gremlin compiler does not
2345
2345
  * natively express the `union(outE, inE.has(bidirectional))` shape that
2346
2346
  * would push this filter server-side, so it stays client-side; the
2347
- * observable contract (which edges count toward "outbound" given
2347
+ * observable contract (which edges count toward `'out'` given
2348
2348
  * bidirectionality) is preserved.
2349
2349
  *
2350
2350
  * Round-trips per call: `options.depth` (one per layer). The previous BFS
@@ -2390,17 +2390,17 @@ Verify the ARM/Bicep template that provisioned the container.`
2390
2390
  const isTarget = rel.targetEntityId === fv;
2391
2391
  let matchesDirection = false;
2392
2392
  let connectedId;
2393
- if (isSource && (options.direction === "outbound" || options.direction === "both")) {
2393
+ if (isSource && (options.direction === "out" || options.direction === "both")) {
2394
2394
  matchesDirection = true;
2395
2395
  connectedId = rel.targetEntityId;
2396
- } else if (isTarget && (options.direction === "inbound" || options.direction === "both")) {
2396
+ } else if (isTarget && (options.direction === "in" || options.direction === "both")) {
2397
2397
  matchesDirection = true;
2398
2398
  connectedId = rel.sourceEntityId;
2399
2399
  } else if (rel.bidirectional) {
2400
- if (isSource && options.direction === "inbound") {
2400
+ if (isSource && options.direction === "in") {
2401
2401
  matchesDirection = true;
2402
2402
  connectedId = rel.targetEntityId;
2403
- } else if (isTarget && options.direction === "outbound") {
2403
+ } else if (isTarget && options.direction === "out") {
2404
2404
  matchesDirection = true;
2405
2405
  connectedId = rel.sourceEntityId;
2406
2406
  }
@@ -2642,7 +2642,7 @@ Verify the ARM/Bicep template that provisioned the container.`
2642
2642
  }
2643
2643
  return projected;
2644
2644
  };
2645
- const projectStoredRelationship = (rel, direction = "outbound") => ({
2645
+ const projectStoredRelationship = (rel, direction = "out") => ({
2646
2646
  id: rel.id,
2647
2647
  type: rel.relationshipType,
2648
2648
  sourceEntityId: rel.sourceEntityId,
@@ -2653,10 +2653,27 @@ Verify the ARM/Bicep template that provisioned the container.`
2653
2653
  let entities = [];
2654
2654
  let relationships;
2655
2655
  let paths;
2656
+ const rangeRowCount = spec.returnMode === "all" ? raw.allEntities.length + raw.allRelationships.length : 0;
2656
2657
  if (spec.returnMode === "terminal") {
2657
2658
  entities = raw.terminalEntities.map(projectStoredEntity);
2658
2659
  relationships = void 0;
2659
2660
  } else if (spec.returnMode === "all") {
2661
+ const missingIds = /* @__PURE__ */ new Set();
2662
+ for (const rel of raw.allRelationships) {
2663
+ if (!raw.entityMap.has(rel.sourceEntityId)) {
2664
+ missingIds.add(rel.sourceEntityId);
2665
+ }
2666
+ if (!raw.entityMap.has(rel.targetEntityId)) {
2667
+ missingIds.add(rel.targetEntityId);
2668
+ }
2669
+ }
2670
+ if (missingIds.size > 0) {
2671
+ const fetched = await this.getEntities(repositoryId, [...missingIds]);
2672
+ for (const stored of fetched.values()) {
2673
+ raw.allEntities.push(stored);
2674
+ raw.entityMap.set(stored.id, stored);
2675
+ }
2676
+ }
2660
2677
  entities = raw.allEntities.map(projectStoredEntity);
2661
2678
  relationships = raw.allRelationships.map((r) => projectStoredRelationship(r));
2662
2679
  } else {
@@ -2684,7 +2701,7 @@ Verify the ARM/Bicep template that provisioned the container.`
2684
2701
  })
2685
2702
  }));
2686
2703
  relationships = Array.from(raw.relationshipMap.values()).map(
2687
- (rel) => projectStoredRelationship(rel, raw.pathRelFirstDirection.get(rel.id) ?? "outbound")
2704
+ (rel) => projectStoredRelationship(rel, raw.pathRelFirstDirection.get(rel.id) ?? "out")
2688
2705
  );
2689
2706
  }
2690
2707
  const limit = spec.limit ?? 50;
@@ -2696,6 +2713,8 @@ Verify the ARM/Bicep template that provisioned the container.`
2696
2713
  } else {
2697
2714
  total = entities.length;
2698
2715
  }
2716
+ const paginationSignal = spec.returnMode === "all" ? rangeRowCount : total;
2717
+ const truncated = paginationSignal >= limit;
2699
2718
  const queryMetadata = {
2700
2719
  executionTimeMs: raw.executionTimeMs,
2701
2720
  resourceCost: raw.requestCharge != null ? { units: "RU", value: raw.requestCharge } : void 0,
@@ -2705,8 +2724,8 @@ Verify the ARM/Bicep template that provisioned the container.`
2705
2724
  maxResults: limit,
2706
2725
  maxDepth: spec.steps?.length
2707
2726
  },
2708
- truncated: total >= limit,
2709
- truncationReason: total >= limit ? "result_limit" : void 0
2727
+ truncated,
2728
+ truncationReason: truncated ? "result_limit" : void 0
2710
2729
  };
2711
2730
  return {
2712
2731
  entities,
@@ -2714,7 +2733,7 @@ Verify the ARM/Bicep template that provisioned the container.`
2714
2733
  paths,
2715
2734
  total,
2716
2735
  returned: total,
2717
- hasMore: total >= limit,
2736
+ hasMore: truncated,
2718
2737
  queryMetadata
2719
2738
  };
2720
2739
  }
@@ -2805,7 +2824,7 @@ Verify the ARM/Bicep template that provisioned the container.`
2805
2824
  const stored = relationshipFromGremlin(props);
2806
2825
  raw.relationshipMap.set(stored.id, stored);
2807
2826
  pathRelIds.push(stored.id);
2808
- const direction = lastVertexId === stored.sourceEntityId ? "outbound" : "inbound";
2827
+ const direction = lastVertexId === stored.sourceEntityId ? "out" : "in";
2809
2828
  pathRelDirections.push(direction);
2810
2829
  if (!raw.pathRelFirstDirection.has(stored.id)) {
2811
2830
  raw.pathRelFirstDirection.set(stored.id, direction);