@lucern/graph-primitives 1.0.19 → 1.0.21

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.
@@ -7,7 +7,7 @@ import { componentsGeneric, anyApi, internalMutationGeneric, mutationGeneric, qu
7
7
  import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
8
8
  import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
9
9
  import { assertSchemaEnumValue } from '@lucern/contracts/schema-helpers/enumValidation';
10
- import { generateGlobalId } from '@lucern/contracts/ids';
10
+ import { generateGlobalId, generateUuidV7 } from '@lucern/contracts/ids';
11
11
  import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
12
12
 
13
13
  // src/epistemicBeliefs.helpers.ts
@@ -2081,9 +2081,16 @@ function scopeFromTopicAnchor(topicNode) {
2081
2081
  }
2082
2082
  async function createRequiredBeliefTopicEdge(ctx, args) {
2083
2083
  const topicGlobalId = args.topicNode.globalId;
2084
- const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:belongs_to`;
2085
2084
  const now = Date.now();
2086
- const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", edgeGlobalId)).first();
2085
+ const existingEdges = await ctx.db.query("epistemicEdges").withIndex(
2086
+ "by_from_to",
2087
+ (q) => q.eq("fromNodeId", String(args.beliefNodeId)).eq(
2088
+ "toNodeId",
2089
+ String(args.topicNode._id)
2090
+ )
2091
+ ).collect();
2092
+ const existing = existingEdges.find((edge) => edge.edgeType === "belongs_to");
2093
+ const edgeGlobalId = cleanString(existing?.globalId) ?? generateUuidV7();
2087
2094
  if (!existing) {
2088
2095
  await ctx.db.insert("epistemicEdges", {
2089
2096
  globalId: edgeGlobalId,
@@ -2097,7 +2104,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
2097
2104
  context: "Belief creation topic anchor invariant.",
2098
2105
  reasoningMethod: "implicit",
2099
2106
  derivationType: "topic_scope_invariant",
2100
- metadata: { invariant: "belief.topic_edge_required" },
2107
+ metadata: {
2108
+ invariant: "belief.topic_edge_required",
2109
+ edgeUuid: edgeGlobalId,
2110
+ fromUuid: args.beliefGlobalId,
2111
+ toUuid: topicGlobalId
2112
+ },
2101
2113
  createdBy: args.createdBy,
2102
2114
  createdAt: now,
2103
2115
  updatedAt: now,
@@ -2126,7 +2138,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
2126
2138
  toNodeType: "topic",
2127
2139
  fromLayer: "L3",
2128
2140
  toLayer: args.topicNode.epistemicLayer ?? "ontological",
2129
- metadata: { invariant: "belief.topic_edge_required" }
2141
+ metadata: {
2142
+ invariant: "belief.topic_edge_required",
2143
+ edgeUuid: edgeGlobalId,
2144
+ fromUuid: args.beliefGlobalId,
2145
+ toUuid: topicGlobalId
2146
+ }
2130
2147
  });
2131
2148
  }
2132
2149