@lucern/graph-primitives 1.0.17 → 1.0.19
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/entityLifecycle.js +1 -12
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/epistemicAnswers.js +1 -12
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/epistemicBeliefs.core.js +4 -15
- package/dist/epistemicBeliefs.core.js.map +1 -1
- package/dist/epistemicBeliefs.internal.js +4 -15
- package/dist/epistemicBeliefs.internal.js.map +1 -1
- package/dist/epistemicBeliefs.js +62 -19
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicBeliefs.links.js +59 -16
- package/dist/epistemicBeliefs.links.js.map +1 -1
- package/dist/epistemicBeliefs.topicAnchor.js +3 -3
- package/dist/epistemicBeliefs.topicAnchor.js.map +1 -1
- package/dist/epistemicContracts.handlers.js +1 -12
- package/dist/epistemicContracts.handlers.js.map +1 -1
- package/dist/epistemicContracts.js +1 -12
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/epistemicEdgeCreation.js +1 -12
- package/dist/epistemicEdgeCreation.js.map +1 -1
- package/dist/epistemicEdges.helpers.d.ts +1 -1
- package/dist/epistemicEvidence.js +1 -12
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/epistemicEvidenceMutations.js +1 -12
- package/dist/epistemicEvidenceMutations.js.map +1 -1
- package/dist/epistemicHelpers.js +1 -12
- package/dist/epistemicHelpers.js.map +1 -1
- package/dist/epistemicNodeCreation.js +1 -10
- package/dist/epistemicNodeCreation.js.map +1 -1
- package/dist/epistemicQuestions.create.js +1 -12
- package/dist/epistemicQuestions.create.js.map +1 -1
- package/dist/epistemicQuestions.evidence.js +1 -12
- package/dist/epistemicQuestions.evidence.js.map +1 -1
- package/dist/epistemicQuestions.js +1 -12
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/epistemicQuestions.tail.js +1 -12
- package/dist/epistemicQuestions.tail.js.map +1 -1
- package/dist/epistemicSources.js +1 -12
- package/dist/epistemicSources.js.map +1 -1
- package/dist/globalId-4y9SPpC_.d.ts +10 -0
- package/dist/globalId.d.ts +1 -1
- package/dist/globalId.js +1 -13
- package/dist/globalId.js.map +1 -1
- package/dist/helpers.js +1 -12
- package/dist/helpers.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +65 -18
- package/dist/index.js.map +1 -1
- package/dist/proof-attestation.json +1 -1
- package/package.json +4 -4
- package/dist/globalId-DKh9d_uD.d.ts +0 -20
package/dist/epistemicBeliefs.js
CHANGED
|
@@ -7,6 +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
11
|
import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
|
|
11
12
|
|
|
12
13
|
// src/epistemicBeliefs.helpers.ts
|
|
@@ -2080,7 +2081,7 @@ function scopeFromTopicAnchor(topicNode) {
|
|
|
2080
2081
|
}
|
|
2081
2082
|
async function createRequiredBeliefTopicEdge(ctx, args) {
|
|
2082
2083
|
const topicGlobalId = args.topicNode.globalId;
|
|
2083
|
-
const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:
|
|
2084
|
+
const edgeGlobalId = `edge:${args.beliefGlobalId}:${topicGlobalId}:belongs_to`;
|
|
2084
2085
|
const now = Date.now();
|
|
2085
2086
|
const existing = await ctx.db.query("epistemicEdges").withIndex("by_globalId", (q) => q.eq("globalId", edgeGlobalId)).first();
|
|
2086
2087
|
if (!existing) {
|
|
@@ -2090,7 +2091,7 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
|
|
|
2090
2091
|
toNodeId: String(args.topicNode._id),
|
|
2091
2092
|
sourceGlobalId: args.beliefGlobalId,
|
|
2092
2093
|
targetGlobalId: topicGlobalId,
|
|
2093
|
-
edgeType: "
|
|
2094
|
+
edgeType: "belongs_to",
|
|
2094
2095
|
weight: 1,
|
|
2095
2096
|
confidence: 1,
|
|
2096
2097
|
context: "Belief creation topic anchor invariant.",
|
|
@@ -2114,7 +2115,7 @@ async function createRequiredBeliefTopicEdge(ctx, args) {
|
|
|
2114
2115
|
globalId: edgeGlobalId,
|
|
2115
2116
|
fromGlobalId: args.beliefGlobalId,
|
|
2116
2117
|
toGlobalId: topicGlobalId,
|
|
2117
|
-
edgeType: "
|
|
2118
|
+
edgeType: "belongs_to",
|
|
2118
2119
|
weight: 1,
|
|
2119
2120
|
confidence: 1,
|
|
2120
2121
|
context: "Belief creation topic anchor invariant.",
|
|
@@ -2158,18 +2159,6 @@ async function scheduleEmbeddingGeneration(args) {
|
|
|
2158
2159
|
}
|
|
2159
2160
|
}
|
|
2160
2161
|
|
|
2161
|
-
// src/globalId.ts
|
|
2162
|
-
function generateGlobalId() {
|
|
2163
|
-
const bytes = new Uint8Array(16);
|
|
2164
|
-
crypto.getRandomValues(bytes);
|
|
2165
|
-
bytes[6] = bytes[6] & 15 | 64;
|
|
2166
|
-
bytes[8] = bytes[8] & 63 | 128;
|
|
2167
|
-
const hex = Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join(
|
|
2168
|
-
""
|
|
2169
|
-
);
|
|
2170
|
-
return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
|
|
2171
|
-
}
|
|
2172
|
-
|
|
2173
2162
|
// src/epistemicBeliefs.core.ts
|
|
2174
2163
|
var create = mutation({
|
|
2175
2164
|
args: {
|
|
@@ -3674,6 +3663,39 @@ var getWithEvidence = query({
|
|
|
3674
3663
|
};
|
|
3675
3664
|
}
|
|
3676
3665
|
});
|
|
3666
|
+
async function collectRelationshipNodeRefs(ctx, nodeId) {
|
|
3667
|
+
const refs = /* @__PURE__ */ new Set([String(nodeId)]);
|
|
3668
|
+
const node = await ctx.db.get(nodeId);
|
|
3669
|
+
const globalId = typeof node?.globalId === "string" ? node.globalId.trim() : "";
|
|
3670
|
+
if (globalId.length > 0) {
|
|
3671
|
+
refs.add(globalId);
|
|
3672
|
+
}
|
|
3673
|
+
return [...refs];
|
|
3674
|
+
}
|
|
3675
|
+
function endpointMatches(q, fields, refs) {
|
|
3676
|
+
return q.or(
|
|
3677
|
+
...fields.flatMap(
|
|
3678
|
+
(field) => refs.map((ref) => q.eq(q.field(field), ref))
|
|
3679
|
+
)
|
|
3680
|
+
);
|
|
3681
|
+
}
|
|
3682
|
+
async function resolveRelationshipEndpoint(ctx, endpointId, globalEndpointId) {
|
|
3683
|
+
const candidates = [endpointId, globalEndpointId].map((value) => typeof value === "string" ? value.trim() : "").filter((value, index, values) => value.length > 0 && values.indexOf(value) === index);
|
|
3684
|
+
for (const candidate of candidates) {
|
|
3685
|
+
try {
|
|
3686
|
+
const direct = await ctx.db.get(candidate);
|
|
3687
|
+
if (direct) {
|
|
3688
|
+
return direct;
|
|
3689
|
+
}
|
|
3690
|
+
} catch {
|
|
3691
|
+
}
|
|
3692
|
+
const byGlobalId = await ctx.db.query("epistemicNodes").withIndex("by_globalId", (q) => q.eq("globalId", candidate)).first();
|
|
3693
|
+
if (byGlobalId) {
|
|
3694
|
+
return byGlobalId;
|
|
3695
|
+
}
|
|
3696
|
+
}
|
|
3697
|
+
return null;
|
|
3698
|
+
}
|
|
3677
3699
|
var getRelationships = query({
|
|
3678
3700
|
args: {
|
|
3679
3701
|
nodeId: v.id("epistemicNodes"),
|
|
@@ -3688,17 +3710,38 @@ var getRelationships = query({
|
|
|
3688
3710
|
incoming: [],
|
|
3689
3711
|
outgoing: []
|
|
3690
3712
|
};
|
|
3713
|
+
const nodeRefs = await collectRelationshipNodeRefs(ctx, args.nodeId);
|
|
3691
3714
|
if (direction === "in" || direction === "both") {
|
|
3692
|
-
const inEdges = await ctx.db.query("epistemicEdges").filter(
|
|
3715
|
+
const inEdges = await ctx.db.query("epistemicEdges").filter(
|
|
3716
|
+
(q) => endpointMatches(
|
|
3717
|
+
q,
|
|
3718
|
+
["toNodeId", "targetGlobalId", "toGlobalId", "toUuid"],
|
|
3719
|
+
nodeRefs
|
|
3720
|
+
)
|
|
3721
|
+
).collect();
|
|
3693
3722
|
for (const edge of inEdges) {
|
|
3694
|
-
const sourceNode = await
|
|
3723
|
+
const sourceNode = await resolveRelationshipEndpoint(
|
|
3724
|
+
ctx,
|
|
3725
|
+
edge.fromNodeId,
|
|
3726
|
+
edge.sourceGlobalId ?? edge.fromGlobalId ?? edge.fromUuid
|
|
3727
|
+
);
|
|
3695
3728
|
results.incoming.push({ edge, node: sourceNode });
|
|
3696
3729
|
}
|
|
3697
3730
|
}
|
|
3698
3731
|
if (direction === "out" || direction === "both") {
|
|
3699
|
-
const outEdges = await ctx.db.query("epistemicEdges").filter(
|
|
3732
|
+
const outEdges = await ctx.db.query("epistemicEdges").filter(
|
|
3733
|
+
(q) => endpointMatches(
|
|
3734
|
+
q,
|
|
3735
|
+
["fromNodeId", "sourceGlobalId", "fromGlobalId", "fromUuid"],
|
|
3736
|
+
nodeRefs
|
|
3737
|
+
)
|
|
3738
|
+
).collect();
|
|
3700
3739
|
for (const edge of outEdges) {
|
|
3701
|
-
const targetNode =
|
|
3740
|
+
const targetNode = await resolveRelationshipEndpoint(
|
|
3741
|
+
ctx,
|
|
3742
|
+
edge.toNodeId,
|
|
3743
|
+
edge.targetGlobalId ?? edge.toGlobalId ?? edge.toUuid
|
|
3744
|
+
);
|
|
3702
3745
|
results.outgoing.push({ edge, node: targetNode });
|
|
3703
3746
|
}
|
|
3704
3747
|
}
|