@lucern/graph-primitives 1.0.19 → 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.
@@ -4,7 +4,7 @@ import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistr
4
4
  import { assertSchemaEnumValue } from '@lucern/contracts/schema-helpers/enumValidation';
5
5
  import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
6
6
  import { componentsGeneric, anyApi, internalQueryGeneric, internalMutationGeneric } from 'convex/server';
7
- import { generateGlobalId } from '@lucern/contracts/ids';
7
+ import { generateGlobalId, generateUuidV7 } from '@lucern/contracts/ids';
8
8
  import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
9
9
  import { normalizeTupleContradictionPolicy, confidenceFromSL } from '@lucern/confidence';
10
10
  import '@lucern/access-control/access';
@@ -301,9 +301,16 @@ function scopeFromTopicAnchor(topicNode) {
301
301
  }
302
302
  async function createRequiredBeliefTopicEdge(ctx, args) {
303
303
  const topicGlobalId = args.topicNode.globalId;
304
- const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:belongs_to`;
305
304
  const now = Date.now();
306
- const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", edgeGlobalId)).first();
305
+ const existingEdges = await ctx.db.query("epistemicEdges").withIndex(
306
+ "by_from_to",
307
+ (q) => q.eq("fromNodeId", String(args.beliefNodeId)).eq(
308
+ "toNodeId",
309
+ String(args.topicNode._id)
310
+ )
311
+ ).collect();
312
+ const existing = existingEdges.find((edge) => edge.edgeType === "belongs_to");
313
+ const edgeGlobalId = cleanString(existing?.globalId) ?? generateUuidV7();
307
314
  if (!existing) {
308
315
  await ctx.db.insert("epistemicEdges", {
309
316
  globalId: edgeGlobalId,
@@ -317,7 +324,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
317
324
  context: "Belief creation topic anchor invariant.",
318
325
  reasoningMethod: "implicit",
319
326
  derivationType: "topic_scope_invariant",
320
- metadata: { invariant: "belief.topic_edge_required" },
327
+ metadata: {
328
+ invariant: "belief.topic_edge_required",
329
+ edgeUuid: edgeGlobalId,
330
+ fromUuid: args.beliefGlobalId,
331
+ toUuid: topicGlobalId
332
+ },
321
333
  createdBy: args.createdBy,
322
334
  createdAt: now,
323
335
  updatedAt: now,
@@ -346,7 +358,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
346
358
  toNodeType: "topic",
347
359
  fromLayer: "L3",
348
360
  toLayer: args.topicNode.epistemicLayer ?? "ontological",
349
- metadata: { invariant: "belief.topic_edge_required" }
361
+ metadata: {
362
+ invariant: "belief.topic_edge_required",
363
+ edgeUuid: edgeGlobalId,
364
+ fromUuid: args.beliefGlobalId,
365
+ toUuid: topicGlobalId
366
+ }
350
367
  });
351
368
  }
352
369
  function normalizeScopeValue2(value) {