@lucern/graph-primitives 1.0.18 → 1.0.20

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 { normalizeTupleContradictionPolicy, createInheritedContractRecord, confi
7
7
  import '@lucern/access-control/audience';
8
8
  import { getCurrentUserId } from '@lucern/access-control/auth';
9
9
  import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
10
- import { generateGlobalId } from '@lucern/contracts/ids';
10
+ import { generateGlobalId, generateUuidV7 } from '@lucern/contracts/ids';
11
11
 
12
12
  // src/epistemicBeliefs.core.ts
13
13
 
@@ -1071,9 +1071,16 @@ function scopeFromTopicAnchor(topicNode) {
1071
1071
  }
1072
1072
  async function createRequiredBeliefTopicEdge(ctx, args) {
1073
1073
  const topicGlobalId = args.topicNode.globalId;
1074
- const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:scoped_by`;
1075
1074
  const now = Date.now();
1076
- const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", edgeGlobalId)).first();
1075
+ const existingEdges = await ctx.db.query("epistemicEdges").withIndex(
1076
+ "by_from_to",
1077
+ (q) => q.eq("fromNodeId", String(args.beliefNodeId)).eq(
1078
+ "toNodeId",
1079
+ String(args.topicNode._id)
1080
+ )
1081
+ ).collect();
1082
+ const existing = existingEdges.find((edge) => edge.edgeType === "belongs_to");
1083
+ const edgeGlobalId = cleanString(existing?.globalId) ?? generateUuidV7();
1077
1084
  if (!existing) {
1078
1085
  await ctx.db.insert("epistemicEdges", {
1079
1086
  globalId: edgeGlobalId,
@@ -1081,13 +1088,18 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
1081
1088
  toNodeId: String(args.topicNode._id),
1082
1089
  sourceGlobalId: args.beliefGlobalId,
1083
1090
  targetGlobalId: topicGlobalId,
1084
- edgeType: "scoped_by",
1091
+ edgeType: "belongs_to",
1085
1092
  weight: 1,
1086
1093
  confidence: 1,
1087
1094
  context: "Belief creation topic anchor invariant.",
1088
1095
  reasoningMethod: "implicit",
1089
1096
  derivationType: "topic_scope_invariant",
1090
- metadata: { invariant: "belief.topic_edge_required" },
1097
+ metadata: {
1098
+ invariant: "belief.topic_edge_required",
1099
+ edgeUuid: edgeGlobalId,
1100
+ fromUuid: args.beliefGlobalId,
1101
+ toUuid: topicGlobalId
1102
+ },
1091
1103
  createdBy: args.createdBy,
1092
1104
  createdAt: now,
1093
1105
  updatedAt: now,
@@ -1105,7 +1117,7 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
1105
1117
  globalId: edgeGlobalId,
1106
1118
  fromGlobalId: args.beliefGlobalId,
1107
1119
  toGlobalId: topicGlobalId,
1108
- edgeType: "scoped_by",
1120
+ edgeType: "belongs_to",
1109
1121
  weight: 1,
1110
1122
  confidence: 1,
1111
1123
  context: "Belief creation topic anchor invariant.",
@@ -1116,7 +1128,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
1116
1128
  toNodeType: "topic",
1117
1129
  fromLayer: "L3",
1118
1130
  toLayer: args.topicNode.epistemicLayer ?? "ontological",
1119
- metadata: { invariant: "belief.topic_edge_required" }
1131
+ metadata: {
1132
+ invariant: "belief.topic_edge_required",
1133
+ edgeUuid: edgeGlobalId,
1134
+ fromUuid: args.beliefGlobalId,
1135
+ toUuid: topicGlobalId
1136
+ }
1120
1137
  });
1121
1138
  }
1122
1139