@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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/convex.ts","../src/epistemicBeliefs.topicAnchor.ts"],"names":[],"mappings":";;;AAc0B,iBAAA;AACnB,IAAM,QAAA,GAAW,MAAA;;;ACDxB,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,IAAA,GAAO,MAAA,GAAS,CAAA,GACtD,KAAA,CAAM,IAAA,EAAK,GACX,MAAA;AACN;AAEA,SAAS,oBAAoB,QAAA,EAA4B;AACvD,EAAA,MAAM,UAAA,GAAa,SAAS,IAAA,EAAK;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,EAAC;AAAA,EACV;AACA,EAAA,MAAM,UAAA,GAAa,CAAC,UAAU,CAAA;AAC9B,EAAA,IAAI,UAAA,CAAW,UAAA,CAAW,MAAM,CAAA,EAAG;AACjC,IAAA,UAAA,CAAW,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,CAAC,CAAC,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,UAAU,CAAC,CAAA;AAChC;AAEO,SAAS,iBAAiB,IAAA,EAA4C;AAC3E,EAAA,OACE,WAAA,CAAY,IAAA,CAAK,aAAa,CAAA,IAC9B,WAAA,CAAY,KAAK,WAAW,CAAA,IAC5B,WAAA,CAAY,IAAA,CAAK,OAAO,CAAA;AAE5B;AAEA,eAAsB,0BAAA,CACpB,KACA,QAAA,EACuB;AACvB,EAAA,KAAA,MAAW,SAAA,IAAa,mBAAA,CAAoB,QAAQ,CAAA,EAAG;AACrD,IAAA,IAAI;AACF,MAAA,MAAM,MAAA,GAAS,MAAM,GAAA,CAAI,EAAA,CAAG,IAAI,SAAiC,CAAA;AACjE,MAA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AA,IAChE,QAAA,EAAU,YAAA;AAAA,IACV,cAAc,IAAA,CAAK,cAAA;AAAA,IACnB,UAAA,EAAY,aAAA;AAAA,IACZ,QAAA,EAAU,WAAA;AAAA,IACV,MAAA,EAAQ,CAAA;AAAA,IACR,UAAA,EAAY,CAAA;AAAA,IACZ,OAAA,EAAS,yCAAA;AAAA,IACT,SAAA,EAAW,WAAA,CAAY,IAAA,CAAK,SAAA,CAAU,SAAS,CAAA;AAAA,IAC/C,OAAA,EAAS,aAAA;AAAA,IACT,WAAW,IAAA,CAAK,SAAA;AAAA,IAChB,YAAA,EAAc,QAAA;AAAA,IACd,UAAA,EAAY,OAAA;AAAA,IACZ,SAAA,EAAW,IAAA;AAAA,IACX,OAAA,EAAS,IAAA,CAAK,SAAA,CAAU,cAAA,IAAkB,aAAA;AAAA,IAC1C,QAAA,EAAU,EAAE,SAAA,EAAW,4BAAA;AAA6B,GACrD,CAAA;AACH","file":"epistemicBeliefs.topicAnchor.js","sourcesContent":["import {\n actionGeneric,\n anyApi,\n componentsGeneric,\n httpActionGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\n\nexport const api = anyApi as any;\nexport const components = componentsGeneric() as any;\nexport const internal = anyApi as any;\n\nexport type TableNames = string;\nexport type Id<TableName extends TableNames = string> = GenericId<TableName>;\nexport type Doc<TableName extends TableNames = string> = any;\nexport type DataModel = any;\ntype IndexRangeBuilder = {\n field(fieldName: string): string;\n eq(fieldName: string, value: unknown): IndexRangeBuilder;\n gt(fieldName: string, value: unknown): IndexRangeBuilder;\n gte(fieldName: string, value: unknown): IndexRangeBuilder;\n lt(fieldName: string, value: unknown): IndexRangeBuilder;\n lte(fieldName: string, value: unknown): IndexRangeBuilder;\n};\ntype FilterBuilder = {\n eq(left: unknown, right: unknown): unknown;\n neq(left: unknown, right: unknown): unknown;\n gt(left: unknown, right: unknown): unknown;\n gte(left: unknown, right: unknown): unknown;\n lt(left: unknown, right: unknown): unknown;\n lte(left: unknown, right: unknown): unknown;\n and(...clauses: unknown[]): unknown;\n or(...clauses: unknown[]): unknown;\n field(fieldName: string): unknown;\n};\ntype QueryInitializer<TableName extends TableNames> = {\n withIndex(\n indexName: string,\n range?: (q: any) => unknown\n ): QueryInitializer<TableName>;\n filter(predicate: (q: any) => unknown): QueryInitializer<TableName>;\n order(direction: \"asc\" | \"desc\"): QueryInitializer<TableName>;\n collect(): Promise<Doc<TableName>[]>;\n take(limit: number): Promise<Doc<TableName>[]>;\n first(): Promise<Doc<TableName> | null>;\n unique(): Promise<Doc<TableName> | null>;\n};\nexport type DatabaseReader = {\n get<TableName extends TableNames>(\n id: Id<TableName>\n ): Promise<Doc<TableName> | null>;\n query<TableName extends TableNames>(\n tableName: TableName\n ): QueryInitializer<TableName>;\n normalizeId?<TableName extends TableNames>(\n tableName: TableName,\n id: string\n ): Id<TableName> | null;\n};\nexport type DatabaseWriter = DatabaseReader & {\n insert<TableName extends TableNames>(\n tableName: TableName,\n value: Record<string, unknown>\n ): Promise<Id<TableName>>;\n patch<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n replace<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n delete<TableName extends TableNames>(id: Id<TableName>): Promise<void>;\n};\ntype Scheduler = {\n runAfter(delayMs: number, functionReference: unknown, args?: unknown): Promise<void>;\n};\ntype AuthReader = {\n getUserIdentity(): Promise<unknown>;\n};\ntype RuntimeInvoker = {\n runQuery(functionReference: unknown, args?: unknown): Promise<any>;\n runMutation(functionReference: unknown, args?: unknown): Promise<any>;\n runAction(functionReference: unknown, args?: unknown): Promise<any>;\n};\nexport type QueryCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseReader;\n scheduler: Scheduler;\n};\nexport type MutationCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseWriter;\n scheduler: Scheduler;\n};\nexport type ActionCtx = RuntimeInvoker & {\n auth: AuthReader;\n scheduler: Scheduler;\n};\n\ntype ConvexFunctionBuilder<Ctx> = <\n Definition extends { handler?: (ctx: Ctx, args: any) => any },\n>(\n definition: Definition\n) => any;\n\nexport const action = actionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const httpAction =\n httpActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalAction =\n internalActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalMutation =\n internalMutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const internalQuery =\n internalQueryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\nexport const mutation =\n mutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const query = queryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\n","import type { Doc, Id, MutationCtx } from \"./convex\";\nimport { internal } from \"./convex\";\n\ntype TopicAnchorInput = {\n topicId?: string;\n topicNodeId?: string;\n topicGlobalId?: string;\n};\n\ntype TopicNodeDoc = Doc<\"epistemicNodes\"> & {\n globalId: string;\n nodeType: \"topic\";\n};\n\nfunction cleanString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim().length > 0\n ? value.trim()\n : undefined;\n}\n\nfunction topicNodeCandidates(topicRef: string): string[] {\n const normalized = topicRef.trim();\n if (!normalized) {\n return [];\n }\n const candidates = [normalized];\n if (normalized.startsWith(\"top_\")) {\n candidates.push(normalized.slice(4));\n }\n return [...new Set(candidates)];\n}\n\nexport function readTopicNodeRef(args: TopicAnchorInput): string | undefined {\n return (\n cleanString(args.topicGlobalId) ??\n cleanString(args.topicNodeId) ??\n cleanString(args.topicId)\n );\n}\n\nexport async function resolveRequiredTopicAnchor(\n ctx: MutationCtx,\n topicRef: string,\n): Promise<TopicNodeDoc> {\n for (const candidate of topicNodeCandidates(topicRef)) {\n try {\n const direct = await ctx.db.get(candidate as Id<\"epistemicNodes\">);\n if (direct?.nodeType === \"topic\" && cleanString(direct.globalId)) {\n return direct as TopicNodeDoc;\n }\n } catch (_) {\n // Not a component-local epistemicNodes _id; try the globalId index next.\n }\n\n const byGlobalId = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", candidate))\n .first();\n if (byGlobalId?.nodeType === \"topic\" && cleanString(byGlobalId.globalId)) {\n return byGlobalId as TopicNodeDoc;\n }\n }\n\n throw new Error(\n \"Belief creation requires topicGlobalId or topicNodeId for a topic node in epistemicNodes. Legacy topics-table IDs are not valid belief anchors.\",\n );\n}\n\nexport function scopeFromTopicAnchor(topicNode: TopicNodeDoc) {\n return {\n topicId: topicNode.globalId,\n projectId: cleanString(topicNode.projectId),\n tenantId: cleanString(topicNode.tenantId),\n workspaceId: cleanString(topicNode.workspaceId),\n source: \"topic\" as const,\n };\n}\n\nexport async function createRequiredBeliefTopicEdge(\n ctx: MutationCtx,\n args: {\n beliefNodeId: Id<\"epistemicNodes\">;\n beliefGlobalId: string;\n topicNode: TopicNodeDoc;\n createdBy: string;\n },\n) {\n const topicGlobalId = args.topicNode.globalId;\n const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:scoped_by`;\n const now = Date.now();\n\n const existing = await ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", edgeGlobalId))\n .first();\n if (!existing) {\n await ctx.db.insert(\"epistemicEdges\", {\n globalId: edgeGlobalId,\n fromNodeId: String(args.beliefNodeId),\n toNodeId: String(args.topicNode._id),\n sourceGlobalId: args.beliefGlobalId,\n targetGlobalId: topicGlobalId,\n edgeType: \"scoped_by\",\n weight: 1,\n confidence: 1,\n context: \"Belief creation topic anchor invariant.\",\n reasoningMethod: \"implicit\",\n derivationType: \"topic_scope_invariant\",\n metadata: { invariant: \"belief.topic_edge_required\" },\n createdBy: args.createdBy,\n createdAt: now,\n updatedAt: now,\n projectId: cleanString(args.topicNode.projectId),\n topicId: topicGlobalId,\n tenantId: cleanString(args.topicNode.tenantId),\n workspaceId: cleanString(args.topicNode.workspaceId),\n fromNodeType: \"belief\",\n toNodeType: \"topic\",\n fromLayer: \"L3\",\n toLayer: args.topicNode.epistemicLayer ?? \"ontological\",\n } as any);\n }\n\n await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {\n globalId: edgeGlobalId,\n fromGlobalId: args.beliefGlobalId,\n toGlobalId: topicGlobalId,\n edgeType: \"scoped_by\",\n weight: 1,\n confidence: 1,\n context: \"Belief creation topic anchor invariant.\",\n projectId: cleanString(args.topicNode.projectId),\n topicId: topicGlobalId,\n createdBy: args.createdBy,\n fromNodeType: \"belief\",\n toNodeType: \"topic\",\n fromLayer: \"L3\",\n toLayer: args.topicNode.epistemicLayer ?? \"ontological\",\n metadata: { invariant: \"belief.topic_edge_required\" },\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/convex.ts","../src/epistemicBeliefs.topicAnchor.ts"],"names":[],"mappings":";;;;AAc0B,iBAAA;AACnB,IAAM,QAAA,GAAW,MAAA;;;ACAxB,SAAS,YAAY,KAAA,EAAoC;AACvD,EAAA,OAAO,OAAO,KAAA,KAAU,QAAA,IAAY,KAAA,CAAM,IAAA,GAAO,MAAA,GAAS,CAAA,GACtD,KAAA,CAAM,IAAA,EAAK,GACX,MAAA;AACN;AAEA,SAAS,oBAAoB,QAAA,EAA4B;AACvD,EAAA,MAAM,UAAA,GAAa,SAAS,IAAA,EAAK;AACjC,EAAA,IAAI,CAAC,UAAA,EAAY;AACf,IAAA,OAAO,EAAC;AAAA,EACV;AACA,EAAA,MAAM,UAAA,GAAa,CAAC,UAAU,CAAA;AAC9B,EAAA,IAAI,UAAA,CAAW,UAAA,CAAW,MAAM,CAAA,EAAG;AACjC,IAAA,UAAA,CAAW,IAAA,CAAK,UAAA,CAAW,KAAA,CAAM,CAAC,CAAC,CAAA;AAAA,EACrC;AACA,EAAA,OAAO,CAAC,GAAG,IAAI,GAAA,CAAI,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kB,aAAA;AAAA,IAC1C,QAAA,EAAU;AAAA,MACR,SAAA,EAAW,4BAAA;AAAA,MACX,QAAA,EAAU,YAAA;AAAA,MACV,UAAU,IAAA,CAAK,cAAA;AAAA,MACf,MAAA,EAAQ;AAAA;AACV,GACD,CAAA;AACH","file":"epistemicBeliefs.topicAnchor.js","sourcesContent":["import {\n actionGeneric,\n anyApi,\n componentsGeneric,\n httpActionGeneric,\n internalActionGeneric,\n internalMutationGeneric,\n internalQueryGeneric,\n mutationGeneric,\n queryGeneric,\n} from \"convex/server\";\nimport type { GenericId } from \"convex/values\";\n\nexport const api = anyApi as any;\nexport const components = componentsGeneric() as any;\nexport const internal = anyApi as any;\n\nexport type TableNames = string;\nexport type Id<TableName extends TableNames = string> = GenericId<TableName>;\nexport type Doc<TableName extends TableNames = string> = any;\nexport type DataModel = any;\ntype IndexRangeBuilder = {\n field(fieldName: string): string;\n eq(fieldName: string, value: unknown): IndexRangeBuilder;\n gt(fieldName: string, value: unknown): IndexRangeBuilder;\n gte(fieldName: string, value: unknown): IndexRangeBuilder;\n lt(fieldName: string, value: unknown): IndexRangeBuilder;\n lte(fieldName: string, value: unknown): IndexRangeBuilder;\n};\ntype FilterBuilder = {\n eq(left: unknown, right: unknown): unknown;\n neq(left: unknown, right: unknown): unknown;\n gt(left: unknown, right: unknown): unknown;\n gte(left: unknown, right: unknown): unknown;\n lt(left: unknown, right: unknown): unknown;\n lte(left: unknown, right: unknown): unknown;\n and(...clauses: unknown[]): unknown;\n or(...clauses: unknown[]): unknown;\n field(fieldName: string): unknown;\n};\ntype QueryInitializer<TableName extends TableNames> = {\n withIndex(\n indexName: string,\n range?: (q: any) => unknown\n ): QueryInitializer<TableName>;\n filter(predicate: (q: any) => unknown): QueryInitializer<TableName>;\n order(direction: \"asc\" | \"desc\"): QueryInitializer<TableName>;\n collect(): Promise<Doc<TableName>[]>;\n take(limit: number): Promise<Doc<TableName>[]>;\n first(): Promise<Doc<TableName> | null>;\n unique(): Promise<Doc<TableName> | null>;\n};\nexport type DatabaseReader = {\n get<TableName extends TableNames>(\n id: Id<TableName>\n ): Promise<Doc<TableName> | null>;\n query<TableName extends TableNames>(\n tableName: TableName\n ): QueryInitializer<TableName>;\n normalizeId?<TableName extends TableNames>(\n tableName: TableName,\n id: string\n ): Id<TableName> | null;\n};\nexport type DatabaseWriter = DatabaseReader & {\n insert<TableName extends TableNames>(\n tableName: TableName,\n value: Record<string, unknown>\n ): Promise<Id<TableName>>;\n patch<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n replace<TableName extends TableNames>(\n id: Id<TableName>,\n value: Record<string, unknown>\n ): Promise<void>;\n delete<TableName extends TableNames>(id: Id<TableName>): Promise<void>;\n};\ntype Scheduler = {\n runAfter(delayMs: number, functionReference: unknown, args?: unknown): Promise<void>;\n};\ntype AuthReader = {\n getUserIdentity(): Promise<unknown>;\n};\ntype RuntimeInvoker = {\n runQuery(functionReference: unknown, args?: unknown): Promise<any>;\n runMutation(functionReference: unknown, args?: unknown): Promise<any>;\n runAction(functionReference: unknown, args?: unknown): Promise<any>;\n};\nexport type QueryCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseReader;\n scheduler: Scheduler;\n};\nexport type MutationCtx = RuntimeInvoker & {\n auth: AuthReader;\n db: DatabaseWriter;\n scheduler: Scheduler;\n};\nexport type ActionCtx = RuntimeInvoker & {\n auth: AuthReader;\n scheduler: Scheduler;\n};\n\ntype ConvexFunctionBuilder<Ctx> = <\n Definition extends { handler?: (ctx: Ctx, args: any) => any },\n>(\n definition: Definition\n) => any;\n\nexport const action = actionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const httpAction =\n httpActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalAction =\n internalActionGeneric as unknown as ConvexFunctionBuilder<ActionCtx>;\nexport const internalMutation =\n internalMutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const internalQuery =\n internalQueryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\nexport const mutation =\n mutationGeneric as unknown as ConvexFunctionBuilder<MutationCtx>;\nexport const query = queryGeneric as unknown as ConvexFunctionBuilder<QueryCtx>;\n","import type { Doc, Id, MutationCtx } from \"./convex\";\nimport { internal } from \"./convex\";\nimport { generateUuidV7 } from \"./globalId\";\n\ntype TopicAnchorInput = {\n topicId?: string;\n topicNodeId?: string;\n topicGlobalId?: string;\n};\n\ntype TopicNodeDoc = Doc<\"epistemicNodes\"> & {\n globalId: string;\n nodeType: \"topic\";\n};\n\nfunction cleanString(value: unknown): string | undefined {\n return typeof value === \"string\" && value.trim().length > 0\n ? value.trim()\n : undefined;\n}\n\nfunction topicNodeCandidates(topicRef: string): string[] {\n const normalized = topicRef.trim();\n if (!normalized) {\n return [];\n }\n const candidates = [normalized];\n if (normalized.startsWith(\"top_\")) {\n candidates.push(normalized.slice(4));\n }\n return [...new Set(candidates)];\n}\n\nexport function readTopicNodeRef(args: TopicAnchorInput): string | undefined {\n return (\n cleanString(args.topicGlobalId) ??\n cleanString(args.topicNodeId) ??\n cleanString(args.topicId)\n );\n}\n\nexport async function resolveRequiredTopicAnchor(\n ctx: MutationCtx,\n topicRef: string,\n): Promise<TopicNodeDoc> {\n for (const candidate of topicNodeCandidates(topicRef)) {\n try {\n const direct = await ctx.db.get(candidate as Id<\"epistemicNodes\">);\n if (direct?.nodeType === \"topic\" && cleanString(direct.globalId)) {\n return direct as TopicNodeDoc;\n }\n } catch (_) {\n // Not a component-local epistemicNodes _id; try the globalId index next.\n }\n\n const byGlobalId = await ctx.db\n .query(\"epistemicNodes\")\n .withIndex(\"by_globalId\", (q) => q.eq(\"globalId\", candidate))\n .first();\n if (byGlobalId?.nodeType === \"topic\" && cleanString(byGlobalId.globalId)) {\n return byGlobalId as TopicNodeDoc;\n }\n }\n\n throw new Error(\n \"Belief creation requires topicGlobalId or topicNodeId for a topic node in epistemicNodes. Legacy topics-table IDs are not valid belief anchors.\",\n );\n}\n\nexport function scopeFromTopicAnchor(topicNode: TopicNodeDoc) {\n return {\n topicId: topicNode.globalId,\n projectId: cleanString(topicNode.projectId),\n tenantId: cleanString(topicNode.tenantId),\n workspaceId: cleanString(topicNode.workspaceId),\n source: \"topic\" as const,\n };\n}\n\nexport async function createRequiredBeliefTopicEdge(\n ctx: MutationCtx,\n args: {\n beliefNodeId: Id<\"epistemicNodes\">;\n beliefGlobalId: string;\n topicNode: TopicNodeDoc;\n createdBy: string;\n },\n) {\n const topicGlobalId = args.topicNode.globalId;\n const now = Date.now();\n\n const existingEdges = await ctx.db\n .query(\"epistemicEdges\")\n .withIndex(\"by_from_to\", (q) =>\n q.eq(\"fromNodeId\", String(args.beliefNodeId)).eq(\n \"toNodeId\",\n String(args.topicNode._id),\n ),\n )\n .collect();\n const existing = existingEdges.find((edge) => edge.edgeType === \"belongs_to\");\n const edgeGlobalId = cleanString(existing?.globalId) ?? generateUuidV7();\n\n if (!existing) {\n await ctx.db.insert(\"epistemicEdges\", {\n globalId: edgeGlobalId,\n fromNodeId: String(args.beliefNodeId),\n toNodeId: String(args.topicNode._id),\n sourceGlobalId: args.beliefGlobalId,\n targetGlobalId: topicGlobalId,\n edgeType: \"belongs_to\",\n weight: 1,\n confidence: 1,\n context: \"Belief creation topic anchor invariant.\",\n reasoningMethod: \"implicit\",\n derivationType: \"topic_scope_invariant\",\n metadata: {\n invariant: \"belief.topic_edge_required\",\n edgeUuid: edgeGlobalId,\n fromUuid: args.beliefGlobalId,\n toUuid: topicGlobalId,\n },\n createdBy: args.createdBy,\n createdAt: now,\n updatedAt: now,\n projectId: cleanString(args.topicNode.projectId),\n topicId: topicGlobalId,\n tenantId: cleanString(args.topicNode.tenantId),\n workspaceId: cleanString(args.topicNode.workspaceId),\n fromNodeType: \"belief\",\n toNodeType: \"topic\",\n fromLayer: \"L3\",\n toLayer: args.topicNode.epistemicLayer ?? \"ontological\",\n } as any);\n }\n\n await ctx.scheduler.runAfter(0, internal.neo4jEdgeAPI.createEdge, {\n globalId: edgeGlobalId,\n fromGlobalId: args.beliefGlobalId,\n toGlobalId: topicGlobalId,\n edgeType: \"belongs_to\",\n weight: 1,\n confidence: 1,\n context: \"Belief creation topic anchor invariant.\",\n projectId: cleanString(args.topicNode.projectId),\n topicId: topicGlobalId,\n createdBy: args.createdBy,\n fromNodeType: \"belief\",\n toNodeType: \"topic\",\n fromLayer: \"L3\",\n toLayer: args.topicNode.epistemicLayer ?? \"ontological\",\n metadata: {\n invariant: \"belief.topic_edge_required\",\n edgeUuid: edgeGlobalId,\n fromUuid: args.beliefGlobalId,\n toUuid: topicGlobalId,\n },\n });\n}\n"]}
@@ -15,7 +15,7 @@ declare const subjectiveOpinionValidator: convex_values.VObject<{
15
15
  u: convex_values.VFloat64<number, "required">;
16
16
  a: convex_values.VFloat64<number, "required">;
17
17
  }, "required", "b" | "d" | "u" | "a">;
18
- declare const edgeTypeValidator: convex_values.VUnion<"supports" | "informs" | "depends_on" | "derived_from" | "contains" | "tests" | "based_on_belief" | "based_on_question" | "blocked_by_contradiction" | "informed_by_theme" | "works_at" | "invested_in" | "competes_with" | "participates_in" | "founded_by" | "evaluates" | "performs" | "function_in" | "impacts" | "raised_from" | "mentioned_in" | "perspective_on" | "supersedes" | "responds_to" | "belongs_to" | "relates_to_thesis" | "plays_theme" | "contradicts" | "scoped_by" | "prerequisite_for" | "parallel_to" | "corroborates" | "extends" | "same_source_as" | "same_theme_as" | "qualifies" | "explores" | "same_as" | "assumes" | "would_predict" | "analogous_to" | "independent_of" | "counterfactual_of" | "cascade_to" | "mutually_exclusive" | "correlates_with" | "amplifies" | "precondition_for" | "in_tension_with" | "cascade_from" | "falsified_by" | "exclusive_with" | "collapses_if" | "strengthened_by" | "weakened_by" | "alternative_to" | "subsumes" | "validated_by" | "required_for" | "blocks", [convex_values.VLiteral<"based_on_belief", "required">, convex_values.VLiteral<"based_on_question", "required">, convex_values.VLiteral<"blocked_by_contradiction", "required">, convex_values.VLiteral<"informed_by_theme", "required">, convex_values.VLiteral<"derived_from", "required">, convex_values.VLiteral<"responds_to", "required">, convex_values.VLiteral<"informs", "required">, convex_values.VLiteral<"tests", "required">, convex_values.VLiteral<"explores", "required">, convex_values.VLiteral<"qualifies", "required">, convex_values.VLiteral<"relates_to_thesis", "required">, convex_values.VLiteral<"belongs_to", "required">, convex_values.VLiteral<"plays_theme", "required">, convex_values.VLiteral<"scoped_by", "required">, convex_values.VLiteral<"evaluates", "required">, convex_values.VLiteral<"perspective_on", "required">, convex_values.VLiteral<"works_at", "required">, convex_values.VLiteral<"mentioned_in", "required">, convex_values.VLiteral<"founded_by", "required">, convex_values.VLiteral<"participates_in", "required">, convex_values.VLiteral<"performs", "required">, convex_values.VLiteral<"function_in", "required">, convex_values.VLiteral<"impacts", "required">, convex_values.VLiteral<"invested_in", "required">, convex_values.VLiteral<"raised_from", "required">, convex_values.VLiteral<"supersedes", "required">, convex_values.VLiteral<"same_as", "required">, convex_values.VLiteral<"depends_on", "required">, convex_values.VLiteral<"supports", "required">, convex_values.VLiteral<"contains", "required">, convex_values.VLiteral<"counterfactual_of", "required">, convex_values.VLiteral<"cascade_to", "required">, convex_values.VLiteral<"cascade_from", "required">, convex_values.VLiteral<"mutually_exclusive", "required">, convex_values.VLiteral<"correlates_with", "required">, convex_values.VLiteral<"amplifies", "required">, convex_values.VLiteral<"precondition_for", "required">, convex_values.VLiteral<"in_tension_with", "required">, convex_values.VLiteral<"falsified_by", "required">, convex_values.VLiteral<"exclusive_with", "required">, convex_values.VLiteral<"contradicts", "required">, convex_values.VLiteral<"collapses_if", "required">, convex_values.VLiteral<"strengthened_by", "required">, convex_values.VLiteral<"weakened_by", "required">, convex_values.VLiteral<"alternative_to", "required">, convex_values.VLiteral<"subsumes", "required">, convex_values.VLiteral<"validated_by", "required">, convex_values.VLiteral<"required_for", "required">, convex_values.VLiteral<"blocks", "required">, convex_values.VLiteral<"prerequisite_for", "required">, convex_values.VLiteral<"parallel_to", "required">, convex_values.VLiteral<"corroborates", "required">, convex_values.VLiteral<"extends", "required">, convex_values.VLiteral<"same_source_as", "required">, convex_values.VLiteral<"same_theme_as", "required">, convex_values.VLiteral<"assumes", "required">, convex_values.VLiteral<"would_predict", "required">, convex_values.VLiteral<"analogous_to", "required">, convex_values.VLiteral<"independent_of", "required">, convex_values.VLiteral<"competes_with", "required">], "required", never>;
18
+ declare const edgeTypeValidator: convex_values.VUnion<"supports" | "informs" | "depends_on" | "derived_from" | "contains" | "tests" | "based_on_belief" | "based_on_question" | "blocked_by_contradiction" | "informed_by_theme" | "works_at" | "invested_in" | "competes_with" | "participates_in" | "founded_by" | "evaluates" | "performs" | "function_in" | "impacts" | "raised_from" | "mentioned_in" | "perspective_on" | "supersedes" | "responds_to" | "belongs_to" | "relates_to_thesis" | "plays_theme" | "contradicts" | "prerequisite_for" | "parallel_to" | "corroborates" | "extends" | "same_source_as" | "same_theme_as" | "qualifies" | "explores" | "scoped_by" | "same_as" | "assumes" | "would_predict" | "analogous_to" | "independent_of" | "counterfactual_of" | "cascade_to" | "mutually_exclusive" | "correlates_with" | "amplifies" | "precondition_for" | "in_tension_with" | "cascade_from" | "falsified_by" | "exclusive_with" | "collapses_if" | "strengthened_by" | "weakened_by" | "alternative_to" | "subsumes" | "validated_by" | "required_for" | "blocks", [convex_values.VLiteral<"based_on_belief", "required">, convex_values.VLiteral<"based_on_question", "required">, convex_values.VLiteral<"blocked_by_contradiction", "required">, convex_values.VLiteral<"informed_by_theme", "required">, convex_values.VLiteral<"derived_from", "required">, convex_values.VLiteral<"responds_to", "required">, convex_values.VLiteral<"informs", "required">, convex_values.VLiteral<"tests", "required">, convex_values.VLiteral<"explores", "required">, convex_values.VLiteral<"qualifies", "required">, convex_values.VLiteral<"relates_to_thesis", "required">, convex_values.VLiteral<"belongs_to", "required">, convex_values.VLiteral<"plays_theme", "required">, convex_values.VLiteral<"scoped_by", "required">, convex_values.VLiteral<"evaluates", "required">, convex_values.VLiteral<"perspective_on", "required">, convex_values.VLiteral<"works_at", "required">, convex_values.VLiteral<"mentioned_in", "required">, convex_values.VLiteral<"founded_by", "required">, convex_values.VLiteral<"participates_in", "required">, convex_values.VLiteral<"performs", "required">, convex_values.VLiteral<"function_in", "required">, convex_values.VLiteral<"impacts", "required">, convex_values.VLiteral<"invested_in", "required">, convex_values.VLiteral<"raised_from", "required">, convex_values.VLiteral<"supersedes", "required">, convex_values.VLiteral<"same_as", "required">, convex_values.VLiteral<"depends_on", "required">, convex_values.VLiteral<"supports", "required">, convex_values.VLiteral<"contains", "required">, convex_values.VLiteral<"counterfactual_of", "required">, convex_values.VLiteral<"cascade_to", "required">, convex_values.VLiteral<"cascade_from", "required">, convex_values.VLiteral<"mutually_exclusive", "required">, convex_values.VLiteral<"correlates_with", "required">, convex_values.VLiteral<"amplifies", "required">, convex_values.VLiteral<"precondition_for", "required">, convex_values.VLiteral<"in_tension_with", "required">, convex_values.VLiteral<"falsified_by", "required">, convex_values.VLiteral<"exclusive_with", "required">, convex_values.VLiteral<"contradicts", "required">, convex_values.VLiteral<"collapses_if", "required">, convex_values.VLiteral<"strengthened_by", "required">, convex_values.VLiteral<"weakened_by", "required">, convex_values.VLiteral<"alternative_to", "required">, convex_values.VLiteral<"subsumes", "required">, convex_values.VLiteral<"validated_by", "required">, convex_values.VLiteral<"required_for", "required">, convex_values.VLiteral<"blocks", "required">, convex_values.VLiteral<"prerequisite_for", "required">, convex_values.VLiteral<"parallel_to", "required">, convex_values.VLiteral<"corroborates", "required">, convex_values.VLiteral<"extends", "required">, convex_values.VLiteral<"same_source_as", "required">, convex_values.VLiteral<"same_theme_as", "required">, convex_values.VLiteral<"assumes", "required">, convex_values.VLiteral<"would_predict", "required">, convex_values.VLiteral<"analogous_to", "required">, convex_values.VLiteral<"independent_of", "required">, convex_values.VLiteral<"competes_with", "required">], "required", never>;
19
19
  declare function buildEdgeStatusSuccessResult(): EdgeStatusResult;
20
20
  declare function buildEdgeNotFoundResult(): EdgeStatusResult;
21
21
  declare function buildEdgeMirrorSkippedResult(): EdgeStatusResult;
package/dist/index.js CHANGED
@@ -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, isUuidV7, generateUuidV7 } from '@lucern/contracts/ids';
10
+ import { generateGlobalId, generateUuidV7, isUuidV7 } from '@lucern/contracts/ids';
11
11
  import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
12
12
  import { scoreEntityTypeMatch, scoreEntityConnection, rankEntityTypeMatches, rankEntityConnections } from '@lucern/contracts/v1/ontologies/v1';
13
13
  import { wordTokenize, wordOverlapScore, tokenizeSearchText, tokenOverlapScore, stemToken, scoreLexicalSignals, scoreLexicalSignal, rerankLexicalWindow, rankWindowScore, prepareLexicalQuery, jaccardSimilarity, bigramTokenize } from '@lucern/contracts/text-matching.contract';
@@ -2515,6 +2515,14 @@ async function resolveForkTriggerEvidence(ctx, args) {
2515
2515
  return { evidenceNodeId: args.triggeringEvidenceId, relation };
2516
2516
  }
2517
2517
 
2518
+ // src/globalId.ts
2519
+ var globalId_exports = {};
2520
+ __export(globalId_exports, {
2521
+ generateGlobalId: () => generateGlobalId,
2522
+ generateUuidV7: () => generateUuidV7,
2523
+ isUuidV7: () => isUuidV7
2524
+ });
2525
+
2518
2526
  // src/epistemicBeliefs.topicAnchor.ts
2519
2527
  function cleanString(value) {
2520
2528
  return typeof value === "string" && value.trim().length > 0 ? value.trim() : void 0;
@@ -2562,9 +2570,16 @@ function scopeFromTopicAnchor(topicNode) {
2562
2570
  }
2563
2571
  async function createRequiredBeliefTopicEdge(ctx, args) {
2564
2572
  const topicGlobalId = args.topicNode.globalId;
2565
- const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:scoped_by`;
2566
2573
  const now = Date.now();
2567
- const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", edgeGlobalId)).first();
2574
+ const existingEdges = await ctx.db.query("epistemicEdges").withIndex(
2575
+ "by_from_to",
2576
+ (q) => q.eq("fromNodeId", String(args.beliefNodeId)).eq(
2577
+ "toNodeId",
2578
+ String(args.topicNode._id)
2579
+ )
2580
+ ).collect();
2581
+ const existing = existingEdges.find((edge) => edge.edgeType === "belongs_to");
2582
+ const edgeGlobalId = cleanString(existing?.globalId) ?? generateUuidV7();
2568
2583
  if (!existing) {
2569
2584
  await ctx.db.insert("epistemicEdges", {
2570
2585
  globalId: edgeGlobalId,
@@ -2572,13 +2587,18 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
2572
2587
  toNodeId: String(args.topicNode._id),
2573
2588
  sourceGlobalId: args.beliefGlobalId,
2574
2589
  targetGlobalId: topicGlobalId,
2575
- edgeType: "scoped_by",
2590
+ edgeType: "belongs_to",
2576
2591
  weight: 1,
2577
2592
  confidence: 1,
2578
2593
  context: "Belief creation topic anchor invariant.",
2579
2594
  reasoningMethod: "implicit",
2580
2595
  derivationType: "topic_scope_invariant",
2581
- metadata: { invariant: "belief.topic_edge_required" },
2596
+ metadata: {
2597
+ invariant: "belief.topic_edge_required",
2598
+ edgeUuid: edgeGlobalId,
2599
+ fromUuid: args.beliefGlobalId,
2600
+ toUuid: topicGlobalId
2601
+ },
2582
2602
  createdBy: args.createdBy,
2583
2603
  createdAt: now,
2584
2604
  updatedAt: now,
@@ -2596,7 +2616,7 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
2596
2616
  globalId: edgeGlobalId,
2597
2617
  fromGlobalId: args.beliefGlobalId,
2598
2618
  toGlobalId: topicGlobalId,
2599
- edgeType: "scoped_by",
2619
+ edgeType: "belongs_to",
2600
2620
  weight: 1,
2601
2621
  confidence: 1,
2602
2622
  context: "Belief creation topic anchor invariant.",
@@ -2607,7 +2627,12 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
2607
2627
  toNodeType: "topic",
2608
2628
  fromLayer: "L3",
2609
2629
  toLayer: args.topicNode.epistemicLayer ?? "ontological",
2610
- metadata: { invariant: "belief.topic_edge_required" }
2630
+ metadata: {
2631
+ invariant: "belief.topic_edge_required",
2632
+ edgeUuid: edgeGlobalId,
2633
+ fromUuid: args.beliefGlobalId,
2634
+ toUuid: topicGlobalId
2635
+ }
2611
2636
  });
2612
2637
  }
2613
2638
 
@@ -2640,14 +2665,6 @@ async function scheduleEmbeddingGeneration(args) {
2640
2665
  }
2641
2666
  }
2642
2667
 
2643
- // src/globalId.ts
2644
- var globalId_exports = {};
2645
- __export(globalId_exports, {
2646
- generateGlobalId: () => generateGlobalId,
2647
- generateUuidV7: () => generateUuidV7,
2648
- isUuidV7: () => isUuidV7
2649
- });
2650
-
2651
2668
  // src/epistemicBeliefs.core.ts
2652
2669
  var create = mutation({
2653
2670
  args: {
@@ -4156,6 +4173,39 @@ var getWithEvidence = query({
4156
4173
  };
4157
4174
  }
4158
4175
  });
4176
+ async function collectRelationshipNodeRefs(ctx, nodeId) {
4177
+ const refs = /* @__PURE__ */ new Set([String(nodeId)]);
4178
+ const node = await ctx.db.get(nodeId);
4179
+ const globalId = typeof node?.globalId === "string" ? node.globalId.trim() : "";
4180
+ if (globalId.length > 0) {
4181
+ refs.add(globalId);
4182
+ }
4183
+ return [...refs];
4184
+ }
4185
+ function endpointMatches(q, fields, refs) {
4186
+ return q.or(
4187
+ ...fields.flatMap(
4188
+ (field) => refs.map((ref) => q.eq(q.field(field), ref))
4189
+ )
4190
+ );
4191
+ }
4192
+ async function resolveRelationshipEndpoint(ctx, endpointId, globalEndpointId) {
4193
+ const candidates = [endpointId, globalEndpointId].map((value) => typeof value === "string" ? value.trim() : "").filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
4194
+ for (const candidate of candidates) {
4195
+ try {
4196
+ const direct = await ctx.db.get(candidate);
4197
+ if (direct) {
4198
+ return direct;
4199
+ }
4200
+ } catch {
4201
+ }
4202
+ const byGlobalId = await ctx.db.query("epistemicNodes").withIndex("by_globalId", (q) => q.eq("globalId", candidate)).first();
4203
+ if (byGlobalId) {
4204
+ return byGlobalId;
4205
+ }
4206
+ }
4207
+ return null;
4208
+ }
4159
4209
  var getRelationships = query({
4160
4210
  args: {
4161
4211
  nodeId: v.id("epistemicNodes"),
@@ -4170,17 +4220,38 @@ var getRelationships = query({
4170
4220
  incoming: [],
4171
4221
  outgoing: []
4172
4222
  };
4223
+ const nodeRefs = await collectRelationshipNodeRefs(ctx, args.nodeId);
4173
4224
  if (direction === "in" || direction === "both") {
4174
- const inEdges = await ctx.db.query("epistemicEdges").filter((q) => q.eq(q.field("toNodeId"), args.nodeId)).collect();
4225
+ const inEdges = await ctx.db.query("epistemicEdges").filter(
4226
+ (q) => endpointMatches(
4227
+ q,
4228
+ ["toNodeId", "targetGlobalId", "toGlobalId", "toUuid"],
4229
+ nodeRefs
4230
+ )
4231
+ ).collect();
4175
4232
  for (const edge of inEdges) {
4176
- const sourceNode = await ctx.db.get(edge.fromNodeId);
4233
+ const sourceNode = await resolveRelationshipEndpoint(
4234
+ ctx,
4235
+ edge.fromNodeId,
4236
+ edge.sourceGlobalId ?? edge.fromGlobalId ?? edge.fromUuid
4237
+ );
4177
4238
  results.incoming.push({ edge, node: sourceNode });
4178
4239
  }
4179
4240
  }
4180
4241
  if (direction === "out" || direction === "both") {
4181
- const outEdges = await ctx.db.query("epistemicEdges").filter((q) => q.eq(q.field("fromNodeId"), args.nodeId)).collect();
4242
+ const outEdges = await ctx.db.query("epistemicEdges").filter(
4243
+ (q) => endpointMatches(
4244
+ q,
4245
+ ["fromNodeId", "sourceGlobalId", "fromGlobalId", "fromUuid"],
4246
+ nodeRefs
4247
+ )
4248
+ ).collect();
4182
4249
  for (const edge of outEdges) {
4183
- const targetNode = edge.toNodeId ? await ctx.db.get(edge.toNodeId) : null;
4250
+ const targetNode = await resolveRelationshipEndpoint(
4251
+ ctx,
4252
+ edge.toNodeId,
4253
+ edge.targetGlobalId ?? edge.toGlobalId ?? edge.toUuid
4254
+ );
4184
4255
  results.outgoing.push({ edge, node: targetNode });
4185
4256
  }
4186
4257
  }