@lucern/graph-primitives 1.0.48 → 1.0.52
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/beliefDecay.js +34 -186
- package/dist/beliefEvidenceLinks.js +32 -187
- package/dist/contradictions.js +34 -187
- package/dist/entityLifecycle.js +88 -205
- package/dist/epistemicAnswers.js +35 -187
- package/dist/epistemicBeliefs.admin.js +34 -187
- package/dist/epistemicBeliefs.backfills.js +34 -188
- package/dist/epistemicBeliefs.confidence.d.ts +1 -1
- package/dist/epistemicBeliefs.confidence.js +32 -188
- package/dist/epistemicBeliefs.core.js +37 -187
- package/dist/epistemicBeliefs.d.ts +1 -1
- package/dist/epistemicBeliefs.helpers.d.ts +1 -1
- package/dist/epistemicBeliefs.helpers.js +34 -186
- package/dist/epistemicBeliefs.internal.js +37 -187
- package/dist/epistemicBeliefs.js +37 -187
- package/dist/epistemicBeliefs.lifecycle.js +32 -188
- package/dist/epistemicBeliefs.links.js +34 -188
- package/dist/epistemicContracts.evaluators.js +34 -188
- package/dist/epistemicContracts.handlers.js +34 -188
- package/dist/epistemicContracts.js +34 -188
- package/dist/epistemicEdges.d.ts +1 -1
- package/dist/epistemicEdges.helpers.d.ts +2 -2
- package/dist/epistemicEdges.js +32 -187
- package/dist/epistemicEdges.mutations.js +34 -186
- package/dist/epistemicEdges.queries.js +35 -188
- package/dist/epistemicEdges.types.d.ts +1 -1
- package/dist/epistemicEvidence.d.ts +1 -1
- package/dist/epistemicEvidence.js +37 -187
- package/dist/epistemicEvidenceHelpers.d.ts +1 -1
- package/dist/epistemicEvidenceHelpers.js +34 -186
- package/dist/epistemicEvidenceMutations.js +37 -187
- package/dist/epistemicEvidenceQueries.js +34 -186
- package/dist/epistemicHelpers.js +4 -1
- package/dist/epistemicInsert.js +4 -1
- package/dist/epistemicNodeCreation.js +4 -1
- package/dist/epistemicNodes.helpers.d.ts +1 -1
- package/dist/epistemicNodes.internal.js +35 -188
- package/dist/epistemicNodes.js +37 -188
- package/dist/epistemicNodes.mutations.js +35 -188
- package/dist/epistemicNodes.queries.js +35 -188
- package/dist/epistemicQuestions.conviction.js +34 -186
- package/dist/epistemicQuestions.create.js +37 -187
- package/dist/epistemicQuestions.d.ts +1 -1
- package/dist/epistemicQuestions.evidence.js +37 -187
- package/dist/epistemicQuestions.helpers.d.ts +1 -1
- package/dist/epistemicQuestions.helpers.js +34 -186
- package/dist/epistemicQuestions.js +37 -187
- package/dist/epistemicQuestions.lifecycle.js +34 -186
- package/dist/epistemicQuestions.queries.js +34 -186
- package/dist/epistemicQuestions.sprint.js +35 -188
- package/dist/epistemicQuestions.tail.js +37 -187
- package/dist/epistemicSources.js +35 -188
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -213
- package/dist/proof-attestation.json +1 -1
- package/dist/questionEvidenceLinks.js +34 -187
- package/dist/scopeResolverCompat.d.ts +1 -1
- package/dist/scopeResolverCompat.js +32 -193
- package/dist/topicOntologyResolver.d.ts +3 -3
- package/dist/topicOntologyResolver.js +57 -18
- package/dist/{topicScope-DJVa0mLa.d.ts → topicScope-CL1IVOmv.d.ts} +2 -2
- package/dist/topicScope.d.ts +1 -1
- package/dist/topicScope.js +32 -193
- package/dist/workflowBridge.js +32 -193
- package/dist/workspaceIsolation.d.ts +1 -1
- package/dist/workspaceIsolation.js +32 -193
- package/package.json +4 -4
package/dist/workflowBridge.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
import { v } from 'convex/values';
|
|
2
|
-
import {
|
|
3
|
-
import { componentsGeneric } from 'convex/server';
|
|
2
|
+
import { isUuidV7 } from '@lucern/contracts/ids';
|
|
4
3
|
|
|
5
4
|
// src/topicScope.ts
|
|
6
|
-
var unsafeApi = unsafeConvexAnyApi(
|
|
7
|
-
"graph-primitives top-level module bundle lacks a committed Convex _generated/api surface"
|
|
8
|
-
);
|
|
9
|
-
var api = unsafeApi;
|
|
10
|
-
componentsGeneric();
|
|
11
5
|
|
|
12
6
|
// src/debug.ts
|
|
13
7
|
function isGraphPrimitiveDebugEnabled() {
|
|
@@ -42,16 +36,36 @@ async function resolveTopicNodeScopeOrNull(ctx, ref) {
|
|
|
42
36
|
if (!node) {
|
|
43
37
|
return null;
|
|
44
38
|
}
|
|
45
|
-
const scopeKey =
|
|
39
|
+
const scopeKey = canonicalTopicGlobalId(node);
|
|
46
40
|
if (!scopeKey) {
|
|
47
|
-
|
|
41
|
+
throw new Error(
|
|
42
|
+
`topic.uuidv7_identity_required: topic node ${ref} is missing a UUIDv7 globalId.`
|
|
43
|
+
);
|
|
48
44
|
}
|
|
45
|
+
const metadata = node.metadata ?? {};
|
|
49
46
|
return {
|
|
50
47
|
topicId: scopeKey,
|
|
51
48
|
projectId: asMappedProjectId(node),
|
|
52
|
-
source: "topic_node"
|
|
49
|
+
source: "topic_node",
|
|
50
|
+
tenantId: normalizeScopeValue(node.tenantId) ?? normalizeScopeValue(metadata.tenantId),
|
|
51
|
+
workspaceId: normalizeScopeValue(node.workspaceId) ?? normalizeScopeValue(metadata.workspaceId)
|
|
53
52
|
};
|
|
54
53
|
}
|
|
54
|
+
function canonicalTopicGlobalId(node) {
|
|
55
|
+
const globalId = normalizeScopeValue(node.globalId);
|
|
56
|
+
if (globalId && isUuidV7(globalId)) {
|
|
57
|
+
return globalId;
|
|
58
|
+
}
|
|
59
|
+
const topicId = normalizeScopeValue(node.topicId);
|
|
60
|
+
return topicId && isUuidV7(topicId) ? topicId : null;
|
|
61
|
+
}
|
|
62
|
+
function requireUuidV7TopicScope(field, value) {
|
|
63
|
+
if (!isUuidV7(value)) {
|
|
64
|
+
throw new Error(
|
|
65
|
+
`topic.uuidv7_required: ${field} must be a UUIDv7 public topic identifier.`
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
55
69
|
function asMappedProjectId(topic) {
|
|
56
70
|
if (!topic) {
|
|
57
71
|
return;
|
|
@@ -73,200 +87,25 @@ function normalizeScopeValue(value) {
|
|
|
73
87
|
const normalized = value.trim();
|
|
74
88
|
return normalized.length > 0 ? normalized : void 0;
|
|
75
89
|
}
|
|
76
|
-
function pickPrimaryTopic(candidates) {
|
|
77
|
-
return [...candidates].sort((a, b) => {
|
|
78
|
-
const depthA = a.depth ?? 9999;
|
|
79
|
-
const depthB = b.depth ?? 9999;
|
|
80
|
-
if (depthA !== depthB) {
|
|
81
|
-
return depthA - depthB;
|
|
82
|
-
}
|
|
83
|
-
const createdA = a.createdAt ?? Number.MAX_SAFE_INTEGER;
|
|
84
|
-
const createdB = b.createdAt ?? Number.MAX_SAFE_INTEGER;
|
|
85
|
-
if (createdA !== createdB) {
|
|
86
|
-
return createdA - createdB;
|
|
87
|
-
}
|
|
88
|
-
return String(a.name || "").localeCompare(String(b.name || ""));
|
|
89
|
-
})[0];
|
|
90
|
-
}
|
|
91
|
-
async function findTopicsByScopeAlias(ctx, scopeId) {
|
|
92
|
-
const query = ctx.db.query("topics");
|
|
93
|
-
try {
|
|
94
|
-
return await query.withIndex(
|
|
95
|
-
"by_graph_scope_project",
|
|
96
|
-
(q) => q.eq(LEGACY_SCOPE_FIELD, scopeId)
|
|
97
|
-
).collect();
|
|
98
|
-
} catch (error) {
|
|
99
|
-
debugGraphPrimitiveFallback(
|
|
100
|
-
"[topicScope] Failed to resolve scope alias via index",
|
|
101
|
-
{
|
|
102
|
-
error,
|
|
103
|
-
scopeId
|
|
104
|
-
}
|
|
105
|
-
);
|
|
106
|
-
const topics = await query.collect();
|
|
107
|
-
return topics.filter((topic) => {
|
|
108
|
-
const normalizedGlobalId = normalizeScopeValue(topic.globalId);
|
|
109
|
-
const mappedProjectId = asMappedProjectId(topic);
|
|
110
|
-
return String(topic._id) === scopeId || normalizedGlobalId === scopeId || mappedProjectId === scopeId;
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
async function tryResolveHostTopicById(ctx, topicId) {
|
|
115
|
-
if (typeof ctx.runQuery !== "function") {
|
|
116
|
-
return null;
|
|
117
|
-
}
|
|
118
|
-
try {
|
|
119
|
-
return await ctx.runQuery(api.topics.get, {
|
|
120
|
-
id: topicId
|
|
121
|
-
}) ?? null;
|
|
122
|
-
} catch (error) {
|
|
123
|
-
debugGraphPrimitiveFallback(
|
|
124
|
-
"[topicScope] Failed to resolve topic by host query",
|
|
125
|
-
{
|
|
126
|
-
error,
|
|
127
|
-
topicId
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
return null;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
async function tryResolveHostTopicByLegacyScope(ctx, legacyScopeId) {
|
|
134
|
-
if (typeof ctx.runQuery !== "function") {
|
|
135
|
-
return null;
|
|
136
|
-
}
|
|
137
|
-
try {
|
|
138
|
-
return await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
139
|
-
projectId: legacyScopeId
|
|
140
|
-
}) ?? null;
|
|
141
|
-
} catch (error) {
|
|
142
|
-
debugGraphPrimitiveFallback(
|
|
143
|
-
"[topicScope] Failed to resolve topic by legacy scope",
|
|
144
|
-
{
|
|
145
|
-
error,
|
|
146
|
-
legacyScopeId
|
|
147
|
-
}
|
|
148
|
-
);
|
|
149
|
-
return null;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
async function resolveInheritedWorkspaceScope(ctx, topic) {
|
|
153
|
-
const MAX_DEPTH = 10;
|
|
154
|
-
let tenantId = normalizeScopeValue(topic.tenantId);
|
|
155
|
-
let workspaceId = normalizeScopeValue(topic.workspaceId);
|
|
156
|
-
if (tenantId && workspaceId) {
|
|
157
|
-
return { tenantId, workspaceId };
|
|
158
|
-
}
|
|
159
|
-
let current = topic;
|
|
160
|
-
for (let i = 0; i < MAX_DEPTH && current?.parentTopicId; i++) {
|
|
161
|
-
current = await ctx.db.get(current.parentTopicId);
|
|
162
|
-
if (!current) {
|
|
163
|
-
break;
|
|
164
|
-
}
|
|
165
|
-
if (!tenantId) {
|
|
166
|
-
tenantId = normalizeScopeValue(current.tenantId);
|
|
167
|
-
}
|
|
168
|
-
if (!workspaceId) {
|
|
169
|
-
workspaceId = normalizeScopeValue(current.workspaceId);
|
|
170
|
-
}
|
|
171
|
-
if (tenantId && workspaceId) {
|
|
172
|
-
break;
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
return { tenantId, workspaceId };
|
|
176
|
-
}
|
|
177
90
|
async function resolveTopicProjectScope(ctx, args) {
|
|
178
91
|
if (args.topicId) {
|
|
179
92
|
return await resolveScopeFromTopicId(ctx, args.topicId);
|
|
180
93
|
}
|
|
181
94
|
if (args.projectId) {
|
|
182
|
-
|
|
95
|
+
throw new Error(
|
|
96
|
+
"topic.uuidv7_required: projectId scope aliases are retired; pass topicId as the UUIDv7 topic globalId."
|
|
97
|
+
);
|
|
183
98
|
}
|
|
184
|
-
throw new Error(
|
|
185
|
-
"Missing scope: provide topicId (preferred) or legacy projectId alias."
|
|
186
|
-
);
|
|
99
|
+
throw new Error("topic.uuidv7_required: Missing scope: provide topicId.");
|
|
187
100
|
}
|
|
188
101
|
async function resolveScopeFromTopicId(ctx, topicId) {
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
193
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, String(topicId));
|
|
102
|
+
const topicGlobalId = String(topicId);
|
|
103
|
+
requireUuidV7TopicScope("topicId", topicGlobalId);
|
|
104
|
+
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, topicGlobalId);
|
|
194
105
|
if (nodeScope) {
|
|
195
106
|
return nodeScope;
|
|
196
107
|
}
|
|
197
|
-
throw new Error(`Topic not found: ${
|
|
198
|
-
}
|
|
199
|
-
async function resolveTopicDocFromTopicId(ctx, topicId) {
|
|
200
|
-
const direct = await tryReadTopicDoc(ctx, topicId, {
|
|
201
|
-
failureLog: "[topicScope] Failed to load topic by direct id",
|
|
202
|
-
idLogKey: "topicId"
|
|
203
|
-
});
|
|
204
|
-
if (direct) {
|
|
205
|
-
return direct;
|
|
206
|
-
}
|
|
207
|
-
const hostTopic = await tryResolveHostTopicById(ctx, String(topicId));
|
|
208
|
-
if (hostTopic) {
|
|
209
|
-
return hostTopic;
|
|
210
|
-
}
|
|
211
|
-
return pickPrimaryTopic(await findTopicsByScopeAlias(ctx, String(topicId))) ?? null;
|
|
212
|
-
}
|
|
213
|
-
async function resolveScopeFromLegacyProjectId(ctx, legacyProjectId) {
|
|
214
|
-
const directTopic = await resolveDirectLegacyProjectTopic(
|
|
215
|
-
ctx,
|
|
216
|
-
legacyProjectId
|
|
217
|
-
);
|
|
218
|
-
if (directTopic) {
|
|
219
|
-
return await buildTopicScope(ctx, directTopic, "topic_inferred", {
|
|
220
|
-
fallbackProjectId: legacyProjectId
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
|
-
const primary = pickPrimaryTopic(
|
|
224
|
-
await findTopicsByScopeAlias(ctx, legacyProjectId)
|
|
225
|
-
);
|
|
226
|
-
if (primary) {
|
|
227
|
-
return await buildTopicScope(ctx, primary, "project_mapped_topic", {
|
|
228
|
-
fallbackProjectId: legacyProjectId
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, legacyProjectId);
|
|
232
|
-
if (nodeScope) {
|
|
233
|
-
return {
|
|
234
|
-
...nodeScope,
|
|
235
|
-
projectId: nodeScope.projectId ?? legacyProjectId
|
|
236
|
-
};
|
|
237
|
-
}
|
|
238
|
-
throw new Error(
|
|
239
|
-
`Legacy project scope ${legacyProjectId} has no mapped topic.`
|
|
240
|
-
);
|
|
241
|
-
}
|
|
242
|
-
async function resolveDirectLegacyProjectTopic(ctx, legacyProjectId) {
|
|
243
|
-
const directTopic = await tryReadTopicDoc(ctx, legacyProjectId, {
|
|
244
|
-
failureLog: "[topicScope] Failed to load direct project topic",
|
|
245
|
-
idLogKey: "projectId"
|
|
246
|
-
});
|
|
247
|
-
return directTopic ?? tryResolveHostTopicByLegacyScope(ctx, legacyProjectId);
|
|
248
|
-
}
|
|
249
|
-
async function tryReadTopicDoc(ctx, id, log) {
|
|
250
|
-
try {
|
|
251
|
-
return await ctx.db.get(id);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
debugGraphPrimitiveFallback(log.failureLog, {
|
|
254
|
-
error,
|
|
255
|
-
[log.idLogKey]: id
|
|
256
|
-
});
|
|
257
|
-
return null;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
async function buildTopicScope(ctx, topic, source, options = {}) {
|
|
261
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
|
|
262
|
-
const mapped = asMappedProjectId(topic);
|
|
263
|
-
return {
|
|
264
|
-
topicId: topic._id,
|
|
265
|
-
...mapped || options.fallbackProjectId ? { projectId: mapped ?? options.fallbackProjectId } : {},
|
|
266
|
-
tenantId: inherited.tenantId,
|
|
267
|
-
workspaceId: inherited.workspaceId,
|
|
268
|
-
source
|
|
269
|
-
};
|
|
108
|
+
throw new Error(`Topic not found: ${topicGlobalId}`);
|
|
270
109
|
}
|
|
271
110
|
({
|
|
272
111
|
projectId: v.optional(v.string()),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { QueryCtx, MutationCtx } from './convex.js';
|
|
2
|
-
import { T as TopicProjectScope } from './topicScope-
|
|
2
|
+
import { T as TopicProjectScope } from './topicScope-CL1IVOmv.js';
|
|
3
3
|
import '@lucern/access-control/convex';
|
|
4
4
|
import '@lucern/contracts/convex/unsafeAnyApi';
|
|
5
5
|
import 'convex/values';
|
|
@@ -1,14 +1,8 @@
|
|
|
1
1
|
import { isNodeType, getLayerForNodeType } from '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
|
|
2
2
|
import { v } from 'convex/values';
|
|
3
|
-
import {
|
|
4
|
-
import { componentsGeneric } from 'convex/server';
|
|
3
|
+
import { isUuidV7 } from '@lucern/contracts/ids';
|
|
5
4
|
|
|
6
5
|
// src/workspaceIsolation.ts
|
|
7
|
-
var unsafeApi = unsafeConvexAnyApi(
|
|
8
|
-
"graph-primitives top-level module bundle lacks a committed Convex _generated/api surface"
|
|
9
|
-
);
|
|
10
|
-
var api = unsafeApi;
|
|
11
|
-
componentsGeneric();
|
|
12
6
|
|
|
13
7
|
// src/debug.ts
|
|
14
8
|
function isGraphPrimitiveDebugEnabled() {
|
|
@@ -43,16 +37,36 @@ async function resolveTopicNodeScopeOrNull(ctx, ref) {
|
|
|
43
37
|
if (!node) {
|
|
44
38
|
return null;
|
|
45
39
|
}
|
|
46
|
-
const scopeKey =
|
|
40
|
+
const scopeKey = canonicalTopicGlobalId(node);
|
|
47
41
|
if (!scopeKey) {
|
|
48
|
-
|
|
42
|
+
throw new Error(
|
|
43
|
+
`topic.uuidv7_identity_required: topic node ${ref} is missing a UUIDv7 globalId.`
|
|
44
|
+
);
|
|
49
45
|
}
|
|
46
|
+
const metadata = node.metadata ?? {};
|
|
50
47
|
return {
|
|
51
48
|
topicId: scopeKey,
|
|
52
49
|
projectId: asMappedProjectId(node),
|
|
53
|
-
source: "topic_node"
|
|
50
|
+
source: "topic_node",
|
|
51
|
+
tenantId: normalizeScopeValue(node.tenantId) ?? normalizeScopeValue(metadata.tenantId),
|
|
52
|
+
workspaceId: normalizeScopeValue(node.workspaceId) ?? normalizeScopeValue(metadata.workspaceId)
|
|
54
53
|
};
|
|
55
54
|
}
|
|
55
|
+
function canonicalTopicGlobalId(node) {
|
|
56
|
+
const globalId = normalizeScopeValue(node.globalId);
|
|
57
|
+
if (globalId && isUuidV7(globalId)) {
|
|
58
|
+
return globalId;
|
|
59
|
+
}
|
|
60
|
+
const topicId = normalizeScopeValue(node.topicId);
|
|
61
|
+
return topicId && isUuidV7(topicId) ? topicId : null;
|
|
62
|
+
}
|
|
63
|
+
function requireUuidV7TopicScope(field, value) {
|
|
64
|
+
if (!isUuidV7(value)) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
`topic.uuidv7_required: ${field} must be a UUIDv7 public topic identifier.`
|
|
67
|
+
);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
56
70
|
function asMappedProjectId(topic) {
|
|
57
71
|
if (!topic) {
|
|
58
72
|
return;
|
|
@@ -74,200 +88,25 @@ function normalizeScopeValue(value) {
|
|
|
74
88
|
const normalized = value.trim();
|
|
75
89
|
return normalized.length > 0 ? normalized : void 0;
|
|
76
90
|
}
|
|
77
|
-
function pickPrimaryTopic(candidates) {
|
|
78
|
-
return [...candidates].sort((a, b) => {
|
|
79
|
-
const depthA = a.depth ?? 9999;
|
|
80
|
-
const depthB = b.depth ?? 9999;
|
|
81
|
-
if (depthA !== depthB) {
|
|
82
|
-
return depthA - depthB;
|
|
83
|
-
}
|
|
84
|
-
const createdA = a.createdAt ?? Number.MAX_SAFE_INTEGER;
|
|
85
|
-
const createdB = b.createdAt ?? Number.MAX_SAFE_INTEGER;
|
|
86
|
-
if (createdA !== createdB) {
|
|
87
|
-
return createdA - createdB;
|
|
88
|
-
}
|
|
89
|
-
return String(a.name || "").localeCompare(String(b.name || ""));
|
|
90
|
-
})[0];
|
|
91
|
-
}
|
|
92
|
-
async function findTopicsByScopeAlias(ctx, scopeId) {
|
|
93
|
-
const query = ctx.db.query("topics");
|
|
94
|
-
try {
|
|
95
|
-
return await query.withIndex(
|
|
96
|
-
"by_graph_scope_project",
|
|
97
|
-
(q) => q.eq(LEGACY_SCOPE_FIELD, scopeId)
|
|
98
|
-
).collect();
|
|
99
|
-
} catch (error) {
|
|
100
|
-
debugGraphPrimitiveFallback(
|
|
101
|
-
"[topicScope] Failed to resolve scope alias via index",
|
|
102
|
-
{
|
|
103
|
-
error,
|
|
104
|
-
scopeId
|
|
105
|
-
}
|
|
106
|
-
);
|
|
107
|
-
const topics = await query.collect();
|
|
108
|
-
return topics.filter((topic) => {
|
|
109
|
-
const normalizedGlobalId = normalizeScopeValue(topic.globalId);
|
|
110
|
-
const mappedProjectId = asMappedProjectId(topic);
|
|
111
|
-
return String(topic._id) === scopeId || normalizedGlobalId === scopeId || mappedProjectId === scopeId;
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
async function tryResolveHostTopicById(ctx, topicId) {
|
|
116
|
-
if (typeof ctx.runQuery !== "function") {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
return await ctx.runQuery(api.topics.get, {
|
|
121
|
-
id: topicId
|
|
122
|
-
}) ?? null;
|
|
123
|
-
} catch (error) {
|
|
124
|
-
debugGraphPrimitiveFallback(
|
|
125
|
-
"[topicScope] Failed to resolve topic by host query",
|
|
126
|
-
{
|
|
127
|
-
error,
|
|
128
|
-
topicId
|
|
129
|
-
}
|
|
130
|
-
);
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
async function tryResolveHostTopicByLegacyScope(ctx, legacyScopeId) {
|
|
135
|
-
if (typeof ctx.runQuery !== "function") {
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
138
|
-
try {
|
|
139
|
-
return await ctx.runQuery(api.topics.getByLegacyScopeId, {
|
|
140
|
-
projectId: legacyScopeId
|
|
141
|
-
}) ?? null;
|
|
142
|
-
} catch (error) {
|
|
143
|
-
debugGraphPrimitiveFallback(
|
|
144
|
-
"[topicScope] Failed to resolve topic by legacy scope",
|
|
145
|
-
{
|
|
146
|
-
error,
|
|
147
|
-
legacyScopeId
|
|
148
|
-
}
|
|
149
|
-
);
|
|
150
|
-
return null;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
async function resolveInheritedWorkspaceScope(ctx, topic) {
|
|
154
|
-
const MAX_DEPTH = 10;
|
|
155
|
-
let tenantId = normalizeScopeValue(topic.tenantId);
|
|
156
|
-
let workspaceId = normalizeScopeValue(topic.workspaceId);
|
|
157
|
-
if (tenantId && workspaceId) {
|
|
158
|
-
return { tenantId, workspaceId };
|
|
159
|
-
}
|
|
160
|
-
let current = topic;
|
|
161
|
-
for (let i = 0; i < MAX_DEPTH && current?.parentTopicId; i++) {
|
|
162
|
-
current = await ctx.db.get(current.parentTopicId);
|
|
163
|
-
if (!current) {
|
|
164
|
-
break;
|
|
165
|
-
}
|
|
166
|
-
if (!tenantId) {
|
|
167
|
-
tenantId = normalizeScopeValue(current.tenantId);
|
|
168
|
-
}
|
|
169
|
-
if (!workspaceId) {
|
|
170
|
-
workspaceId = normalizeScopeValue(current.workspaceId);
|
|
171
|
-
}
|
|
172
|
-
if (tenantId && workspaceId) {
|
|
173
|
-
break;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return { tenantId, workspaceId };
|
|
177
|
-
}
|
|
178
91
|
async function resolveTopicProjectScope(ctx, args) {
|
|
179
92
|
if (args.topicId) {
|
|
180
93
|
return await resolveScopeFromTopicId(ctx, args.topicId);
|
|
181
94
|
}
|
|
182
95
|
if (args.projectId) {
|
|
183
|
-
|
|
96
|
+
throw new Error(
|
|
97
|
+
"topic.uuidv7_required: projectId scope aliases are retired; pass topicId as the UUIDv7 topic globalId."
|
|
98
|
+
);
|
|
184
99
|
}
|
|
185
|
-
throw new Error(
|
|
186
|
-
"Missing scope: provide topicId (preferred) or legacy projectId alias."
|
|
187
|
-
);
|
|
100
|
+
throw new Error("topic.uuidv7_required: Missing scope: provide topicId.");
|
|
188
101
|
}
|
|
189
102
|
async function resolveScopeFromTopicId(ctx, topicId) {
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
}
|
|
194
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, String(topicId));
|
|
103
|
+
const topicGlobalId = String(topicId);
|
|
104
|
+
requireUuidV7TopicScope("topicId", topicGlobalId);
|
|
105
|
+
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, topicGlobalId);
|
|
195
106
|
if (nodeScope) {
|
|
196
107
|
return nodeScope;
|
|
197
108
|
}
|
|
198
|
-
throw new Error(`Topic not found: ${
|
|
199
|
-
}
|
|
200
|
-
async function resolveTopicDocFromTopicId(ctx, topicId) {
|
|
201
|
-
const direct = await tryReadTopicDoc(ctx, topicId, {
|
|
202
|
-
failureLog: "[topicScope] Failed to load topic by direct id",
|
|
203
|
-
idLogKey: "topicId"
|
|
204
|
-
});
|
|
205
|
-
if (direct) {
|
|
206
|
-
return direct;
|
|
207
|
-
}
|
|
208
|
-
const hostTopic = await tryResolveHostTopicById(ctx, String(topicId));
|
|
209
|
-
if (hostTopic) {
|
|
210
|
-
return hostTopic;
|
|
211
|
-
}
|
|
212
|
-
return pickPrimaryTopic(await findTopicsByScopeAlias(ctx, String(topicId))) ?? null;
|
|
213
|
-
}
|
|
214
|
-
async function resolveScopeFromLegacyProjectId(ctx, legacyProjectId) {
|
|
215
|
-
const directTopic = await resolveDirectLegacyProjectTopic(
|
|
216
|
-
ctx,
|
|
217
|
-
legacyProjectId
|
|
218
|
-
);
|
|
219
|
-
if (directTopic) {
|
|
220
|
-
return await buildTopicScope(ctx, directTopic, "topic_inferred", {
|
|
221
|
-
fallbackProjectId: legacyProjectId
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
const primary = pickPrimaryTopic(
|
|
225
|
-
await findTopicsByScopeAlias(ctx, legacyProjectId)
|
|
226
|
-
);
|
|
227
|
-
if (primary) {
|
|
228
|
-
return await buildTopicScope(ctx, primary, "project_mapped_topic", {
|
|
229
|
-
fallbackProjectId: legacyProjectId
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, legacyProjectId);
|
|
233
|
-
if (nodeScope) {
|
|
234
|
-
return {
|
|
235
|
-
...nodeScope,
|
|
236
|
-
projectId: nodeScope.projectId ?? legacyProjectId
|
|
237
|
-
};
|
|
238
|
-
}
|
|
239
|
-
throw new Error(
|
|
240
|
-
`Legacy project scope ${legacyProjectId} has no mapped topic.`
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
async function resolveDirectLegacyProjectTopic(ctx, legacyProjectId) {
|
|
244
|
-
const directTopic = await tryReadTopicDoc(ctx, legacyProjectId, {
|
|
245
|
-
failureLog: "[topicScope] Failed to load direct project topic",
|
|
246
|
-
idLogKey: "projectId"
|
|
247
|
-
});
|
|
248
|
-
return directTopic ?? tryResolveHostTopicByLegacyScope(ctx, legacyProjectId);
|
|
249
|
-
}
|
|
250
|
-
async function tryReadTopicDoc(ctx, id, log) {
|
|
251
|
-
try {
|
|
252
|
-
return await ctx.db.get(id);
|
|
253
|
-
} catch (error) {
|
|
254
|
-
debugGraphPrimitiveFallback(log.failureLog, {
|
|
255
|
-
error,
|
|
256
|
-
[log.idLogKey]: id
|
|
257
|
-
});
|
|
258
|
-
return null;
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
async function buildTopicScope(ctx, topic, source, options = {}) {
|
|
262
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
|
|
263
|
-
const mapped = asMappedProjectId(topic);
|
|
264
|
-
return {
|
|
265
|
-
topicId: topic._id,
|
|
266
|
-
...mapped || options.fallbackProjectId ? { projectId: mapped ?? options.fallbackProjectId } : {},
|
|
267
|
-
tenantId: inherited.tenantId,
|
|
268
|
-
workspaceId: inherited.workspaceId,
|
|
269
|
-
source
|
|
270
|
-
};
|
|
109
|
+
throw new Error(`Topic not found: ${topicGlobalId}`);
|
|
271
110
|
}
|
|
272
111
|
({
|
|
273
112
|
projectId: v.optional(v.string()),
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lucern/graph-primitives",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.52",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -32,9 +32,9 @@
|
|
|
32
32
|
"typecheck": "tsc --noEmit"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@lucern/access-control": "1.0.
|
|
36
|
-
"@lucern/confidence": "1.0.
|
|
37
|
-
"@lucern/contracts": "1.0.
|
|
35
|
+
"@lucern/access-control": "1.0.52",
|
|
36
|
+
"@lucern/confidence": "1.0.52",
|
|
37
|
+
"@lucern/contracts": "1.0.52",
|
|
38
38
|
"convex": "^1.39.1"
|
|
39
39
|
},
|
|
40
40
|
"devDependencies": {
|