@lucern/graph-primitives 1.0.28 → 1.0.30
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-DZ6tkLYq.d.ts → beliefDecay-BmkEk5OJ.d.ts} +3 -3
- package/dist/beliefDecay.d.ts +1 -1
- package/dist/beliefDecay.js +448 -314
- package/dist/beliefDecay.js.map +1 -1
- package/dist/{beliefEvidenceLinks-CWOXxxJg.d.ts → beliefEvidenceLinks-BzfjON_6.d.ts} +13 -13
- package/dist/beliefEvidenceLinks.d.ts +1 -1
- package/dist/beliefEvidenceLinks.js +843 -624
- package/dist/beliefEvidenceLinks.js.map +1 -1
- package/dist/beliefEvidenceLinks.operational.d.ts +7 -5
- package/dist/beliefEvidenceLinks.operational.js +91 -18
- package/dist/beliefEvidenceLinks.operational.js.map +1 -1
- package/dist/beliefLifecycle.js.map +1 -1
- package/dist/confidencePropagationDispatch.d.ts +28 -27
- package/dist/confidencePropagationDispatch.js +157 -99
- package/dist/confidencePropagationDispatch.js.map +1 -1
- package/dist/{contradictions-51VLsESq.d.ts → contradictions-BATPuZTL.d.ts} +10 -10
- package/dist/contradictions.d.ts +1 -1
- package/dist/contradictions.js +398 -228
- package/dist/contradictions.js.map +1 -1
- package/dist/convex.d.ts +65 -30
- package/dist/convex.js +7 -3
- package/dist/convex.js.map +1 -1
- package/dist/debug.js.map +1 -1
- package/dist/edgeValidation.js +293 -85
- package/dist/edgeValidation.js.map +1 -1
- package/dist/edges/contains.d.ts +1 -1
- package/dist/edges/contains.js.map +1 -1
- package/dist/edges/contradicts.d.ts +1 -1
- package/dist/edges/contradicts.js.map +1 -1
- package/dist/edges/{dependsOn.d.ts → depends-on.d.ts} +1 -1
- package/dist/edges/{dependsOn.js → depends-on.js} +4 -4
- package/dist/edges/depends-on.js.map +1 -0
- package/dist/edges/{derivedFrom.d.ts → derived-from.d.ts} +1 -1
- package/dist/edges/{derivedFrom.js → derived-from.js} +3 -3
- package/dist/edges/derived-from.js.map +1 -0
- package/dist/edges/elaborates.d.ts +1 -1
- package/dist/edges/elaborates.js.map +1 -1
- package/dist/edges/index.d.ts +7 -3
- package/dist/edges/index.js +7 -4
- package/dist/edges/index.js.map +1 -1
- package/dist/edges/informs.d.ts +1 -1
- package/dist/edges/informs.js.map +1 -1
- package/dist/edges/{propagationTypes.d.ts → propagation-types.d.ts} +14 -14
- package/dist/edges/{propagationTypes.js → propagation-types.js} +3 -3
- package/dist/edges/propagation-types.js.map +1 -0
- package/dist/edges/refutes.d.ts +1 -1
- package/dist/edges/refutes.js.map +1 -1
- package/dist/edges/supports.d.ts +1 -1
- package/dist/edges/supports.js.map +1 -1
- package/dist/edges/tests.d.ts +1 -1
- package/dist/edges/tests.js.map +1 -1
- package/dist/edges/utils.d.ts +1 -1
- package/dist/edges/utils.js.map +1 -1
- package/dist/embeddingTrigger.d.ts +14 -6
- package/dist/embeddingTrigger.js +11 -14
- package/dist/embeddingTrigger.js.map +1 -1
- package/dist/{entityBridge-DMaKooYn.d.ts → entityBridge-BhVDM3pc.d.ts} +5 -5
- package/dist/entityBridge.d.ts +1 -1
- package/dist/entityBridge.js +602 -225
- package/dist/entityBridge.js.map +1 -1
- package/dist/entityCanonicalMatch.d.ts +14 -12
- package/dist/entityCanonicalMatch.js.map +1 -1
- package/dist/{entityLifecycle-CvgSK5FV.d.ts → entityLifecycle-BsfCz9pS.d.ts} +5 -9
- package/dist/entityLifecycle.d.ts +1 -1
- package/dist/entityLifecycle.js +857 -515
- package/dist/entityLifecycle.js.map +1 -1
- package/dist/{entityValidation-KLZ_Xl2D.d.ts → entityValidation-B1yNEHJx.d.ts} +7 -6
- package/dist/entityValidation.d.ts +3 -1
- package/dist/entityValidation.js +60 -8
- package/dist/entityValidation.js.map +1 -1
- package/dist/{epistemicAnswers-C5ib4z6_.d.ts → epistemicAnswers-f47YMu9U.d.ts} +6 -6
- package/dist/epistemicAnswers.d.ts +1 -1
- package/dist/epistemicAnswers.js +587 -545
- package/dist/epistemicAnswers.js.map +1 -1
- package/dist/epistemicBeliefs.admin.d.ts +8 -8
- package/dist/epistemicBeliefs.admin.js +366 -203
- package/dist/epistemicBeliefs.admin.js.map +1 -1
- package/dist/epistemicBeliefs.backfills.d.ts +8 -8
- package/dist/epistemicBeliefs.backfills.js +655 -308
- package/dist/epistemicBeliefs.backfills.js.map +1 -1
- package/dist/epistemicBeliefs.confidence.d.ts +19 -14
- package/dist/epistemicBeliefs.confidence.js +634 -423
- package/dist/epistemicBeliefs.confidence.js.map +1 -1
- package/dist/epistemicBeliefs.core.d.ts +6 -6
- package/dist/epistemicBeliefs.core.js +719 -411
- package/dist/epistemicBeliefs.core.js.map +1 -1
- package/dist/epistemicBeliefs.d.ts +11 -8
- package/dist/epistemicBeliefs.forkEvidence.d.ts +2 -0
- package/dist/epistemicBeliefs.forkEvidence.js +8 -28
- package/dist/epistemicBeliefs.forkEvidence.js.map +1 -1
- package/dist/epistemicBeliefs.helpers.d.ts +69 -74
- package/dist/epistemicBeliefs.helpers.js +359 -248
- package/dist/epistemicBeliefs.helpers.js.map +1 -1
- package/dist/epistemicBeliefs.internal.d.ts +5 -5
- package/dist/epistemicBeliefs.internal.js +1246 -1044
- package/dist/epistemicBeliefs.internal.js.map +1 -1
- package/dist/epistemicBeliefs.js +4922 -3608
- package/dist/epistemicBeliefs.js.map +1 -1
- package/dist/epistemicBeliefs.lifecycle.d.ts +5 -5
- package/dist/epistemicBeliefs.lifecycle.js +1137 -818
- package/dist/epistemicBeliefs.lifecycle.js.map +1 -1
- package/dist/epistemicBeliefs.links.d.ts +7 -7
- package/dist/epistemicBeliefs.links.js +408 -307
- package/dist/epistemicBeliefs.links.js.map +1 -1
- package/dist/epistemicBeliefs.queries.d.ts +4 -4
- package/dist/epistemicBeliefs.queries.js +175 -20
- package/dist/epistemicBeliefs.queries.js.map +1 -1
- package/dist/epistemicBeliefs.topicAnchor.d.ts +6 -4
- package/dist/epistemicBeliefs.topicAnchor.js +12 -5
- package/dist/epistemicBeliefs.topicAnchor.js.map +1 -1
- package/dist/epistemicContracts.d.ts +28 -3
- package/dist/epistemicContracts.evaluators.d.ts +2 -0
- package/dist/epistemicContracts.evaluators.js +1063 -613
- package/dist/epistemicContracts.evaluators.js.map +1 -1
- package/dist/epistemicContracts.handlers.d.ts +15 -32
- package/dist/epistemicContracts.handlers.js +2086 -1644
- package/dist/epistemicContracts.handlers.js.map +1 -1
- package/dist/epistemicContracts.js +1131 -672
- package/dist/epistemicContracts.js.map +1 -1
- package/dist/epistemicContracts.metrics.d.ts +2 -0
- package/dist/epistemicContracts.metrics.js +375 -158
- package/dist/epistemicContracts.metrics.js.map +1 -1
- package/dist/epistemicContracts.types.d.ts +87 -81
- package/dist/epistemicEdgeCreation.d.ts +2 -0
- package/dist/epistemicEdgeCreation.js +87 -16
- package/dist/epistemicEdgeCreation.js.map +1 -1
- package/dist/{epistemicEdges-BF-cn4i3.d.ts → epistemicEdges-BGBh0QSP.d.ts} +4 -7
- package/dist/epistemicEdges.d.ts +6 -5
- package/dist/epistemicEdges.handlers.d.ts +3 -3
- package/dist/epistemicEdges.handlers.js +129 -24
- package/dist/epistemicEdges.handlers.js.map +1 -1
- package/dist/epistemicEdges.helpers.d.ts +6 -4
- package/dist/epistemicEdges.helpers.js +37 -2
- package/dist/epistemicEdges.helpers.js.map +1 -1
- package/dist/epistemicEdges.js +1969 -1205
- package/dist/epistemicEdges.js.map +1 -1
- package/dist/epistemicEdges.mutations.d.ts +7 -7
- package/dist/epistemicEdges.mutations.js +960 -583
- package/dist/epistemicEdges.mutations.js.map +1 -1
- package/dist/epistemicEdges.queries.d.ts +16 -16
- package/dist/epistemicEdges.queries.js +639 -367
- package/dist/epistemicEdges.queries.js.map +1 -1
- package/dist/epistemicEdges.types.d.ts +10 -8
- package/dist/epistemicEvidence.d.ts +4 -1
- package/dist/epistemicEvidence.js +937 -536
- package/dist/epistemicEvidence.js.map +1 -1
- package/dist/epistemicEvidenceHelpers.d.ts +26 -10
- package/dist/epistemicEvidenceHelpers.js +239 -200
- package/dist/epistemicEvidenceHelpers.js.map +1 -1
- package/dist/epistemicEvidenceMutations.d.ts +8 -8
- package/dist/epistemicEvidenceMutations.js +844 -696
- package/dist/epistemicEvidenceMutations.js.map +1 -1
- package/dist/epistemicEvidenceQueries.d.ts +8 -8
- package/dist/epistemicEvidenceQueries.js +514 -238
- package/dist/epistemicEvidenceQueries.js.map +1 -1
- package/dist/epistemicHelpers.d.ts +4 -2
- package/dist/epistemicHelpers.js +308 -134
- package/dist/epistemicHelpers.js.map +1 -1
- package/dist/epistemicInsert.d.ts +16 -4
- package/dist/epistemicInsert.js +6 -3
- package/dist/epistemicInsert.js.map +1 -1
- package/dist/epistemicLayerRules.d.ts +10 -8
- package/dist/epistemicLayerRules.js +1 -5
- package/dist/epistemicLayerRules.js.map +1 -1
- package/dist/{epistemicLinking-CfE00tHJ.d.ts → epistemicLinking-CsCDv2cN.d.ts} +3 -3
- package/dist/epistemicLinking.d.ts +1 -1
- package/dist/epistemicLinking.js +177 -100
- package/dist/epistemicLinking.js.map +1 -1
- package/dist/epistemicNodeCreation.d.ts +2 -0
- package/dist/epistemicNodeCreation.js +203 -40
- package/dist/epistemicNodeCreation.js.map +1 -1
- package/dist/{epistemicNodes-BCQxpYx_.d.ts → epistemicNodes-CokAgBHg.d.ts} +3 -3
- package/dist/epistemicNodes.d.ts +3 -3
- package/dist/epistemicNodes.helpers.d.ts +24 -15
- package/dist/epistemicNodes.helpers.js.map +1 -1
- package/dist/epistemicNodes.internal.d.ts +6 -6
- package/dist/epistemicNodes.internal.js +389 -319
- package/dist/epistemicNodes.internal.js.map +1 -1
- package/dist/epistemicNodes.js +704 -508
- package/dist/epistemicNodes.js.map +1 -1
- package/dist/epistemicNodes.mutations.d.ts +6 -6
- package/dist/epistemicNodes.mutations.js +564 -467
- package/dist/epistemicNodes.mutations.js.map +1 -1
- package/dist/epistemicNodes.queries.d.ts +8 -8
- package/dist/epistemicNodes.queries.js +311 -314
- package/dist/epistemicNodes.queries.js.map +1 -1
- package/dist/epistemicNodes.validators.d.ts +2 -2
- package/dist/epistemicNodes.validators.js.map +1 -1
- package/dist/epistemicQuestions.conviction.d.ts +8 -8
- package/dist/epistemicQuestions.conviction.js +665 -484
- package/dist/epistemicQuestions.conviction.js.map +1 -1
- package/dist/epistemicQuestions.create.d.ts +4 -4
- package/dist/epistemicQuestions.create.js +640 -612
- package/dist/epistemicQuestions.create.js.map +1 -1
- package/dist/epistemicQuestions.d.ts +8 -5
- package/dist/epistemicQuestions.evidence.d.ts +2 -2
- package/dist/epistemicQuestions.evidence.js +475 -383
- package/dist/epistemicQuestions.evidence.js.map +1 -1
- package/dist/epistemicQuestions.helpers.d.ts +125 -24
- package/dist/epistemicQuestions.helpers.js +240 -209
- package/dist/epistemicQuestions.helpers.js.map +1 -1
- package/dist/epistemicQuestions.js +3474 -2823
- package/dist/epistemicQuestions.js.map +1 -1
- package/dist/epistemicQuestions.lifecycle.d.ts +2 -2
- package/dist/epistemicQuestions.lifecycle.js +607 -546
- package/dist/epistemicQuestions.lifecycle.js.map +1 -1
- package/dist/epistemicQuestions.queries.d.ts +12 -7
- package/dist/epistemicQuestions.queries.js +305 -244
- package/dist/epistemicQuestions.queries.js.map +1 -1
- package/dist/epistemicQuestions.sprint.d.ts +2 -2
- package/dist/epistemicQuestions.sprint.js +600 -394
- package/dist/epistemicQuestions.sprint.js.map +1 -1
- package/dist/epistemicQuestions.tail.d.ts +6 -6
- package/dist/epistemicQuestions.tail.js +572 -433
- package/dist/epistemicQuestions.tail.js.map +1 -1
- package/dist/{epistemicSources-dlKj58Jp.d.ts → epistemicSources-DQtaEkWs.d.ts} +4 -4
- package/dist/epistemicSources.d.ts +1 -1
- package/dist/epistemicSources.js +352 -312
- package/dist/epistemicSources.js.map +1 -1
- package/dist/evaluators/index.d.ts +8 -6
- package/dist/evaluators/index.js +399 -167
- package/dist/evaluators/index.js.map +1 -1
- package/dist/evaluators/lint-checker-evaluator.d.ts +16 -0
- package/dist/evaluators/{lintCheckerEvaluator.js → lint-checker-evaluator.js} +10 -5
- package/dist/evaluators/lint-checker-evaluator.js.map +1 -0
- package/dist/evaluators/{sentryCheckerEvaluator.d.ts → sentry-checker-evaluator.d.ts} +7 -2
- package/dist/evaluators/{sentryCheckerEvaluator.js → sentry-checker-evaluator.js} +3 -3
- package/dist/evaluators/sentry-checker-evaluator.js.map +1 -0
- package/dist/evaluators/shared.d.ts +2 -2
- package/dist/evaluators/shared.js +3 -1
- package/dist/evaluators/shared.js.map +1 -1
- package/dist/evaluators/{testRunnerEvaluator.d.ts → test-runner-evaluator.d.ts} +6 -1
- package/dist/evaluators/{testRunnerEvaluator.js → test-runner-evaluator.js} +6 -4
- package/dist/evaluators/test-runner-evaluator.js.map +1 -0
- package/dist/evaluators/tsc-checker-evaluator.d.ts +16 -0
- package/dist/evaluators/{tscCheckerEvaluator.js → tsc-checker-evaluator.js} +10 -5
- package/dist/evaluators/tsc-checker-evaluator.js.map +1 -0
- package/dist/graphTypes.js +6 -2
- package/dist/graphTypes.js.map +1 -1
- package/dist/helpers.d.ts +2 -0
- package/dist/helpers.js +313 -93
- package/dist/helpers.js.map +1 -1
- package/dist/{index-C-Kyd7hD.d.ts → index-DZxyC9Pb.d.ts} +7 -6
- package/dist/index.d.ts +87 -83
- package/dist/index.js +15677 -10594
- package/dist/index.js.map +1 -1
- package/dist/invariantEnforcement.d.ts +3 -3
- package/dist/invariantEnforcement.js.map +1 -1
- package/dist/logicalRoleInference.d.ts +2 -0
- package/dist/logicalRoleInference.js +1 -1
- package/dist/logicalRoleInference.js.map +1 -1
- package/dist/matcherFeedbackUtils.d.ts +2 -2
- package/dist/matcherFeedbackUtils.js.map +1 -1
- package/dist/{ontology-matching-C6rrz2VP.d.ts → ontology-matching-C-mYFrir.d.ts} +16 -16
- package/dist/ontology-matching.d.ts +1 -1
- package/dist/{ontologyApproval-CFYmqKmk.d.ts → ontologyApproval-BVt0feJi.d.ts} +10 -10
- package/dist/ontologyApproval.d.ts +1 -1
- package/dist/ontologyApproval.js +7 -1
- package/dist/ontologyApproval.js.map +1 -1
- package/dist/ontologyDefinitions.d.ts +14 -24
- package/dist/ontologyDefinitions.js +269 -34
- package/dist/ontologyDefinitions.js.map +1 -1
- package/dist/ontologyHelpers.d.ts +13 -13
- package/dist/ontologyHelpers.js.map +1 -1
- package/dist/{ontologyRegistry-B67rPJ16.d.ts → ontologyRegistry-CljS-ENv.d.ts} +2 -2
- package/dist/ontologyRegistry.d.ts +1 -1
- package/dist/ontologyRegistry.js +34 -6
- package/dist/ontologyRegistry.js.map +1 -1
- package/dist/{projectionReconciliation-jww2fBI0.d.ts → projectionReconciliation-DnrSgHSQ.d.ts} +4 -4
- package/dist/projectionReconciliation.d.ts +1 -1
- package/dist/projectionReconciliation.js +57 -10
- package/dist/projectionReconciliation.js.map +1 -1
- package/dist/{projectionStaleness-CmdbpjVK.d.ts → projectionStaleness-C8ImQ2zP.d.ts} +17 -17
- package/dist/projectionStaleness.d.ts +1 -1
- package/dist/projectionStaleness.js +8 -2
- package/dist/projectionStaleness.js.map +1 -1
- package/dist/proof-attestation.json +1 -1
- package/dist/{questionEvidenceLinks-DFlyPpAj.d.ts → questionEvidenceLinks-_nPRa-LY.d.ts} +10 -10
- package/dist/questionEvidenceLinks.d.ts +1 -1
- package/dist/questionEvidenceLinks.js +564 -347
- package/dist/questionEvidenceLinks.js.map +1 -1
- package/dist/{resolverTypes-CC8Ea2E2.d.ts → resolverTypes-BOXPxLET.d.ts} +8 -7
- package/dist/resolverTypes.d.ts +4 -2
- package/dist/{resolvers-Br1a6eLV.d.ts → resolvers-B1TIBmRO.d.ts} +3 -1
- package/dist/resolvers.d.ts +5 -3
- package/dist/resolvers.js +121 -77
- package/dist/resolvers.js.map +1 -1
- package/dist/scopeResolverCompat.d.ts +10 -7
- package/dist/scopeResolverCompat.js +106 -123
- package/dist/scopeResolverCompat.js.map +1 -1
- package/dist/{text-matching-DNg4M5Wd.d.ts → text-matching-DzFooju6.d.ts} +7 -7
- package/dist/text-matching.d.ts +1 -1
- package/dist/topicOntologyResolver.d.ts +22 -21
- package/dist/topicOntologyResolver.js +54 -32
- package/dist/topicOntologyResolver.js.map +1 -1
- package/dist/topicProjectOverlay.d.ts +30 -20
- package/dist/topicProjectOverlay.js +120 -76
- package/dist/topicProjectOverlay.js.map +1 -1
- package/dist/{topicScope-7zhyeGl7.d.ts → topicScope-DJVa0mLa.d.ts} +22 -7
- package/dist/topicScope.d.ts +3 -1
- package/dist/topicScope.js +104 -119
- package/dist/topicScope.js.map +1 -1
- package/dist/workflowBridge.d.ts +26 -15
- package/dist/workflowBridge.js +140 -144
- package/dist/workflowBridge.js.map +1 -1
- package/dist/workspaceIsolation.d.ts +14 -12
- package/dist/workspaceIsolation.js +108 -122
- package/dist/workspaceIsolation.js.map +1 -1
- package/package.json +4 -4
- package/dist/edges/dependsOn.js.map +0 -1
- package/dist/edges/derivedFrom.js.map +0 -1
- package/dist/edges/propagationTypes.js.map +0 -1
- package/dist/evaluators/lintCheckerEvaluator.d.ts +0 -11
- package/dist/evaluators/lintCheckerEvaluator.js.map +0 -1
- package/dist/evaluators/sentryCheckerEvaluator.js.map +0 -1
- package/dist/evaluators/testRunnerEvaluator.js.map +0 -1
- package/dist/evaluators/tscCheckerEvaluator.d.ts +0 -11
- package/dist/evaluators/tscCheckerEvaluator.js.map +0 -1
- package/dist/{epistemicQuestions-bwHd2FWE.d.ts → epistemicQuestions-Do1fhYm5.d.ts} +4 -4
|
@@ -1,13 +1,17 @@
|
|
|
1
|
-
import { v } from 'convex/values';
|
|
2
1
|
import { checkScopeAccess } from '@lucern/access-control/access';
|
|
3
2
|
import { normalizeAudienceKey, canAudienceClassAccess, classFromAudienceKey } from '@lucern/access-control/audience';
|
|
4
3
|
import { listAudienceRegistryRows } from '@lucern/access-control/audienceRegistry';
|
|
5
4
|
import { permissiveReturn } from '@lucern/contracts/schema-helpers/validators';
|
|
6
|
-
import {
|
|
5
|
+
import { v } from 'convex/values';
|
|
6
|
+
import { unsafeConvexAnyApi } from '@lucern/contracts/convex/unsafeAnyApi';
|
|
7
|
+
import { componentsGeneric, queryGeneric, internalQueryGeneric } from 'convex/server';
|
|
7
8
|
import '@lucern/contracts/schema-helpers/spine/tables/epistemicNodes';
|
|
8
9
|
|
|
9
10
|
// src/epistemicQuestions.queries.ts
|
|
10
|
-
var
|
|
11
|
+
var unsafeApi = unsafeConvexAnyApi(
|
|
12
|
+
"graph-primitives top-level module bundle lacks a committed Convex _generated/api surface"
|
|
13
|
+
);
|
|
14
|
+
var api = unsafeApi;
|
|
11
15
|
componentsGeneric();
|
|
12
16
|
var internalQuery = internalQueryGeneric;
|
|
13
17
|
var query = queryGeneric;
|
|
@@ -61,6 +65,10 @@ function readStringArray(value) {
|
|
|
61
65
|
function readMetadata(topic) {
|
|
62
66
|
return topic.metadata && typeof topic.metadata === "object" ? topic.metadata : {};
|
|
63
67
|
}
|
|
68
|
+
function omitMetadataKey(metadata, key) {
|
|
69
|
+
const { [key]: _omitted, ...rest } = metadata;
|
|
70
|
+
return rest;
|
|
71
|
+
}
|
|
64
72
|
function readLegacyProjectId(value) {
|
|
65
73
|
if (!value) {
|
|
66
74
|
return;
|
|
@@ -141,9 +149,12 @@ async function resolveTopicDoc(ctx, scopeId) {
|
|
|
141
149
|
);
|
|
142
150
|
}
|
|
143
151
|
try {
|
|
144
|
-
const topic = await ctx.runQuery(
|
|
145
|
-
|
|
146
|
-
|
|
152
|
+
const topic = await ctx.runQuery(
|
|
153
|
+
api.topics.getByLegacyScopeId,
|
|
154
|
+
{
|
|
155
|
+
projectId: String(scopeId)
|
|
156
|
+
}
|
|
157
|
+
);
|
|
147
158
|
if (topic?.name !== void 0 && topic?.type !== void 0) {
|
|
148
159
|
return topic;
|
|
149
160
|
}
|
|
@@ -163,8 +174,18 @@ function materializeTopicProjectOverlay(topic, idMode = "legacy") {
|
|
|
163
174
|
const outwardId = idMode === "topic" ? topicId : storageProjectId;
|
|
164
175
|
const visibility = coerceVisibility(topic.visibility) || coerceVisibility(metadata.visibility) || "private";
|
|
165
176
|
const status = coerceStatus(topic.status) || coerceStatus(metadata.status) || "active";
|
|
166
|
-
|
|
167
|
-
|
|
177
|
+
let createdAt = 0;
|
|
178
|
+
if (typeof topic.createdAt === "number") {
|
|
179
|
+
createdAt = topic.createdAt;
|
|
180
|
+
} else if (typeof topic._creationTime === "number") {
|
|
181
|
+
createdAt = topic._creationTime;
|
|
182
|
+
}
|
|
183
|
+
let updatedAt = createdAt;
|
|
184
|
+
if (typeof topic.updatedAt === "number") {
|
|
185
|
+
updatedAt = topic.updatedAt;
|
|
186
|
+
} else if (typeof metadata.updatedAt === "number") {
|
|
187
|
+
updatedAt = metadata.updatedAt;
|
|
188
|
+
}
|
|
168
189
|
return {
|
|
169
190
|
...metadata,
|
|
170
191
|
_id: outwardId,
|
|
@@ -233,90 +254,113 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
|
|
|
233
254
|
if (!topic) {
|
|
234
255
|
return null;
|
|
235
256
|
}
|
|
236
|
-
const
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
257
|
+
const plan = buildTopicProjectOverlayPatchPlan(topic, value);
|
|
258
|
+
await applyTopicProjectOverlayPatch(ctx, topic, plan);
|
|
259
|
+
return materializeTopicProjectOverlay({
|
|
260
|
+
...topic,
|
|
261
|
+
...plan.patch,
|
|
262
|
+
metadata: plan.nextMetadata
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
function buildTopicProjectOverlayPatchPlan(topic, value) {
|
|
266
|
+
const plan = {
|
|
267
|
+
nextMetadata: { ...readMetadata(topic) },
|
|
268
|
+
patch: {},
|
|
269
|
+
topicUpdateArgs: {
|
|
270
|
+
id: String(topic._id)
|
|
271
|
+
}
|
|
240
272
|
};
|
|
241
273
|
for (const [key, rawValue] of Object.entries(value)) {
|
|
242
|
-
|
|
243
|
-
case "_id":
|
|
244
|
-
case "projectId":
|
|
245
|
-
case "topicId":
|
|
246
|
-
case "legacyProjectId":
|
|
247
|
-
case "storageProjectId":
|
|
248
|
-
break;
|
|
249
|
-
case "name":
|
|
250
|
-
case "description":
|
|
251
|
-
patch[key] = rawValue;
|
|
252
|
-
topicUpdateArgs[key] = rawValue;
|
|
253
|
-
break;
|
|
254
|
-
case "tenantId":
|
|
255
|
-
case "workspaceId":
|
|
256
|
-
case "ownerId":
|
|
257
|
-
throw new Error(
|
|
258
|
-
`patchTopicProjectOverlay cannot mutate ${key} via component-owned topics`
|
|
259
|
-
);
|
|
260
|
-
case "status": {
|
|
261
|
-
const status = coerceStatus(rawValue);
|
|
262
|
-
if (status) {
|
|
263
|
-
patch.status = status;
|
|
264
|
-
topicUpdateArgs.status = status;
|
|
265
|
-
}
|
|
266
|
-
break;
|
|
267
|
-
}
|
|
268
|
-
case "visibility": {
|
|
269
|
-
const visibility = coerceVisibility(rawValue);
|
|
270
|
-
if (visibility) {
|
|
271
|
-
patch.visibility = visibility;
|
|
272
|
-
topicUpdateArgs.visibility = visibility;
|
|
273
|
-
}
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
case "type": {
|
|
277
|
-
const projectType = readNonEmptyString(rawValue);
|
|
278
|
-
if (projectType) {
|
|
279
|
-
nextMetadata.projectType = projectType;
|
|
280
|
-
} else {
|
|
281
|
-
delete nextMetadata.projectType;
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
case "updatedAt":
|
|
286
|
-
case "createdAt":
|
|
287
|
-
break;
|
|
288
|
-
default:
|
|
289
|
-
if (rawValue === void 0) {
|
|
290
|
-
delete nextMetadata[key];
|
|
291
|
-
} else {
|
|
292
|
-
nextMetadata[key] = rawValue;
|
|
293
|
-
}
|
|
294
|
-
}
|
|
274
|
+
applyTopicProjectOverlayPatchEntry(plan, key, rawValue);
|
|
295
275
|
}
|
|
296
|
-
patch.updatedAt = Date.now();
|
|
297
|
-
patch.metadata = nextMetadata;
|
|
298
|
-
topicUpdateArgs.metadata = nextMetadata;
|
|
276
|
+
plan.patch.updatedAt = Date.now();
|
|
277
|
+
plan.patch.metadata = plan.nextMetadata;
|
|
278
|
+
plan.topicUpdateArgs.metadata = plan.nextMetadata;
|
|
279
|
+
return plan;
|
|
280
|
+
}
|
|
281
|
+
function applyTopicProjectOverlayPatchEntry(plan, key, rawValue) {
|
|
282
|
+
switch (key) {
|
|
283
|
+
case "_id":
|
|
284
|
+
case "projectId":
|
|
285
|
+
case "topicId":
|
|
286
|
+
case "legacyProjectId":
|
|
287
|
+
case "storageProjectId":
|
|
288
|
+
case "updatedAt":
|
|
289
|
+
case "createdAt":
|
|
290
|
+
return;
|
|
291
|
+
case "name":
|
|
292
|
+
case "description":
|
|
293
|
+
plan.patch[key] = rawValue;
|
|
294
|
+
plan.topicUpdateArgs[key] = rawValue;
|
|
295
|
+
return;
|
|
296
|
+
case "tenantId":
|
|
297
|
+
case "workspaceId":
|
|
298
|
+
case "ownerId":
|
|
299
|
+
throw new Error(
|
|
300
|
+
`patchTopicProjectOverlay cannot mutate ${key} via component-owned topics`
|
|
301
|
+
);
|
|
302
|
+
case "status":
|
|
303
|
+
applyTopicStatusPatch(plan, rawValue);
|
|
304
|
+
return;
|
|
305
|
+
case "visibility":
|
|
306
|
+
applyTopicVisibilityPatch(plan, rawValue);
|
|
307
|
+
return;
|
|
308
|
+
case "type":
|
|
309
|
+
applyTopicProjectTypePatch(plan, rawValue);
|
|
310
|
+
return;
|
|
311
|
+
default:
|
|
312
|
+
applyTopicMetadataPatch(plan, key, rawValue);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
function applyTopicStatusPatch(plan, rawValue) {
|
|
316
|
+
const status = coerceStatus(rawValue);
|
|
317
|
+
if (status) {
|
|
318
|
+
plan.patch.status = status;
|
|
319
|
+
plan.topicUpdateArgs.status = status;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function applyTopicVisibilityPatch(plan, rawValue) {
|
|
323
|
+
const visibility = coerceVisibility(rawValue);
|
|
324
|
+
if (visibility) {
|
|
325
|
+
plan.patch.visibility = visibility;
|
|
326
|
+
plan.topicUpdateArgs.visibility = visibility;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
function applyTopicProjectTypePatch(plan, rawValue) {
|
|
330
|
+
const projectType = readNonEmptyString(rawValue);
|
|
331
|
+
if (projectType) {
|
|
332
|
+
plan.nextMetadata.projectType = projectType;
|
|
333
|
+
return;
|
|
334
|
+
}
|
|
335
|
+
plan.nextMetadata = omitMetadataKey(plan.nextMetadata, "projectType");
|
|
336
|
+
}
|
|
337
|
+
function applyTopicMetadataPatch(plan, key, rawValue) {
|
|
338
|
+
if (rawValue === void 0) {
|
|
339
|
+
plan.nextMetadata = omitMetadataKey(plan.nextMetadata, key);
|
|
340
|
+
return;
|
|
341
|
+
}
|
|
342
|
+
plan.nextMetadata[key] = rawValue;
|
|
343
|
+
}
|
|
344
|
+
async function applyTopicProjectOverlayPatch(ctx, topic, plan) {
|
|
299
345
|
if (typeof ctx.runMutation === "function") {
|
|
300
346
|
try {
|
|
301
|
-
await ctx.runMutation(api.topics.update, topicUpdateArgs);
|
|
347
|
+
await ctx.runMutation(api.topics.update, plan.topicUpdateArgs);
|
|
302
348
|
} catch (error) {
|
|
303
|
-
if (!
|
|
349
|
+
if (!canPatchTopicViaLocalDb(ctx, error)) {
|
|
304
350
|
throw error;
|
|
305
351
|
}
|
|
306
|
-
await ctx.db.patch(
|
|
352
|
+
await ctx.db.patch(topic._id, plan.patch);
|
|
307
353
|
}
|
|
308
354
|
} else if (ctx?.db && typeof ctx.db.patch === "function") {
|
|
309
|
-
await ctx.db.patch(
|
|
355
|
+
await ctx.db.patch(topic._id, plan.patch);
|
|
310
356
|
} else {
|
|
311
357
|
throw new Error(
|
|
312
358
|
"Cannot patch topic without component adapter (ctx.runMutation unavailable)"
|
|
313
359
|
);
|
|
314
360
|
}
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
metadata: nextMetadata
|
|
319
|
-
});
|
|
361
|
+
}
|
|
362
|
+
function canPatchTopicViaLocalDb(ctx, error) {
|
|
363
|
+
return isMissingLucernChildComponentError(error) && Boolean(ctx?.db) && typeof ctx.db?.patch === "function";
|
|
320
364
|
}
|
|
321
365
|
|
|
322
366
|
// src/resolvers.ts
|
|
@@ -344,7 +388,7 @@ async function patchProjectWithTolerance(ctx, projectId, value) {
|
|
|
344
388
|
try {
|
|
345
389
|
await patchTopicProjectOverlay(ctx, projectId, value);
|
|
346
390
|
} catch (error) {
|
|
347
|
-
if (!isAdvisoryTopicPatch(value)
|
|
391
|
+
if (!(isAdvisoryTopicPatch(value) && isMissingLucernChildComponentError2(error))) {
|
|
348
392
|
throw error;
|
|
349
393
|
}
|
|
350
394
|
console.warn(
|
|
@@ -411,13 +455,15 @@ function asMappedProjectId(topic) {
|
|
|
411
455
|
if (!topic) {
|
|
412
456
|
return;
|
|
413
457
|
}
|
|
414
|
-
const directLegacyProjectId = normalizeScopeValue(
|
|
458
|
+
const directLegacyProjectId = normalizeScopeValue(
|
|
459
|
+
topic[LEGACY_SCOPE_FIELD2]
|
|
460
|
+
);
|
|
415
461
|
if (directLegacyProjectId) {
|
|
416
462
|
return directLegacyProjectId;
|
|
417
463
|
}
|
|
418
464
|
const metadata = topic.metadata || {};
|
|
419
465
|
const candidate = metadata[LEGACY_SCOPE_FIELD2] || metadata.legacyProjectId || metadata.projectId || metadata.scopeProjectId;
|
|
420
|
-
return candidate ? candidate : void 0;
|
|
466
|
+
return typeof candidate === "string" ? normalizeScopeValue(candidate) : void 0;
|
|
421
467
|
}
|
|
422
468
|
function normalizeScopeValue(value) {
|
|
423
469
|
if (typeof value !== "string") {
|
|
@@ -442,8 +488,9 @@ function pickPrimaryTopic(candidates) {
|
|
|
442
488
|
})[0];
|
|
443
489
|
}
|
|
444
490
|
async function findTopicsByScopeAlias(ctx, scopeId) {
|
|
491
|
+
const query2 = ctx.db.query("topics");
|
|
445
492
|
try {
|
|
446
|
-
return await
|
|
493
|
+
return await query2.withIndex(
|
|
447
494
|
"by_graph_scope_project",
|
|
448
495
|
(q) => q.eq(LEGACY_SCOPE_FIELD2, scopeId)
|
|
449
496
|
).collect();
|
|
@@ -455,7 +502,7 @@ async function findTopicsByScopeAlias(ctx, scopeId) {
|
|
|
455
502
|
scopeId
|
|
456
503
|
}
|
|
457
504
|
);
|
|
458
|
-
const topics = await
|
|
505
|
+
const topics = await query2.collect();
|
|
459
506
|
return topics.filter((topic) => {
|
|
460
507
|
const normalizedGlobalId = normalizeScopeValue(topic.globalId);
|
|
461
508
|
const mappedProjectId = asMappedProjectId(topic);
|
|
@@ -511,171 +558,119 @@ async function resolveInheritedWorkspaceScope(ctx, topic) {
|
|
|
511
558
|
let current = topic;
|
|
512
559
|
for (let i = 0; i < MAX_DEPTH && current?.parentTopicId; i++) {
|
|
513
560
|
current = await ctx.db.get(current.parentTopicId);
|
|
514
|
-
if (!current)
|
|
561
|
+
if (!current) {
|
|
562
|
+
break;
|
|
563
|
+
}
|
|
515
564
|
if (!tenantId) {
|
|
516
565
|
tenantId = normalizeScopeValue(current.tenantId);
|
|
517
566
|
}
|
|
518
567
|
if (!workspaceId) {
|
|
519
568
|
workspaceId = normalizeScopeValue(current.workspaceId);
|
|
520
569
|
}
|
|
521
|
-
if (tenantId && workspaceId)
|
|
570
|
+
if (tenantId && workspaceId) {
|
|
571
|
+
break;
|
|
572
|
+
}
|
|
522
573
|
}
|
|
523
574
|
return { tenantId, workspaceId };
|
|
524
575
|
}
|
|
525
576
|
async function resolveTopicProjectScope(ctx, args) {
|
|
526
577
|
if (args.topicId) {
|
|
527
|
-
|
|
528
|
-
try {
|
|
529
|
-
topic = await ctx.db.get(
|
|
530
|
-
args.topicId
|
|
531
|
-
);
|
|
532
|
-
} catch (error) {
|
|
533
|
-
debugGraphPrimitiveFallback(
|
|
534
|
-
"[topicScope] Failed to load topic by direct id",
|
|
535
|
-
{
|
|
536
|
-
error,
|
|
537
|
-
topicId: args.topicId
|
|
538
|
-
}
|
|
539
|
-
);
|
|
540
|
-
}
|
|
541
|
-
if (!topic) {
|
|
542
|
-
topic = await tryResolveHostTopicById(ctx, String(args.topicId));
|
|
543
|
-
}
|
|
544
|
-
if (!topic) {
|
|
545
|
-
topic = pickPrimaryTopic(
|
|
546
|
-
await findTopicsByScopeAlias(ctx, String(args.topicId))
|
|
547
|
-
) ?? null;
|
|
548
|
-
}
|
|
549
|
-
if (!topic) {
|
|
550
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(
|
|
551
|
-
ctx,
|
|
552
|
-
String(args.topicId)
|
|
553
|
-
);
|
|
554
|
-
if (nodeScope) {
|
|
555
|
-
return nodeScope;
|
|
556
|
-
}
|
|
557
|
-
throw new Error(`Topic not found: ${String(args.topicId)}`);
|
|
558
|
-
}
|
|
559
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
|
|
560
|
-
const mapped = asMappedProjectId(topic);
|
|
561
|
-
if (mapped) {
|
|
562
|
-
return {
|
|
563
|
-
topicId: topic._id,
|
|
564
|
-
projectId: mapped,
|
|
565
|
-
tenantId: inherited.tenantId,
|
|
566
|
-
workspaceId: inherited.workspaceId,
|
|
567
|
-
source: "topic"
|
|
568
|
-
};
|
|
569
|
-
}
|
|
570
|
-
return {
|
|
571
|
-
topicId: topic._id,
|
|
572
|
-
tenantId: inherited.tenantId,
|
|
573
|
-
workspaceId: inherited.workspaceId,
|
|
574
|
-
source: "topic"
|
|
575
|
-
};
|
|
578
|
+
return await resolveScopeFromTopicId(ctx, args.topicId);
|
|
576
579
|
}
|
|
577
580
|
if (args.projectId) {
|
|
578
|
-
|
|
579
|
-
try {
|
|
580
|
-
directTopic = await ctx.db.get(
|
|
581
|
-
args.projectId
|
|
582
|
-
);
|
|
583
|
-
} catch (error) {
|
|
584
|
-
debugGraphPrimitiveFallback(
|
|
585
|
-
"[topicScope] Failed to load direct project topic",
|
|
586
|
-
{
|
|
587
|
-
error,
|
|
588
|
-
projectId: args.projectId
|
|
589
|
-
}
|
|
590
|
-
);
|
|
591
|
-
}
|
|
592
|
-
if (directTopic) {
|
|
593
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
|
|
594
|
-
const mapped = asMappedProjectId(directTopic);
|
|
595
|
-
return {
|
|
596
|
-
topicId: directTopic._id,
|
|
597
|
-
projectId: mapped ?? args.projectId,
|
|
598
|
-
tenantId: inherited.tenantId,
|
|
599
|
-
workspaceId: inherited.workspaceId,
|
|
600
|
-
source: "topic_inferred"
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
directTopic = await tryResolveHostTopicByLegacyScope(ctx, args.projectId);
|
|
604
|
-
if (directTopic) {
|
|
605
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
|
|
606
|
-
const mapped = asMappedProjectId(directTopic);
|
|
607
|
-
return {
|
|
608
|
-
topicId: directTopic._id,
|
|
609
|
-
projectId: mapped ?? args.projectId,
|
|
610
|
-
tenantId: inherited.tenantId,
|
|
611
|
-
workspaceId: inherited.workspaceId,
|
|
612
|
-
source: "topic_inferred"
|
|
613
|
-
};
|
|
614
|
-
}
|
|
615
|
-
const topics = await findTopicsByScopeAlias(ctx, args.projectId);
|
|
616
|
-
const primary = pickPrimaryTopic(topics);
|
|
617
|
-
if (primary) {
|
|
618
|
-
const inherited = await resolveInheritedWorkspaceScope(ctx, primary);
|
|
619
|
-
return {
|
|
620
|
-
topicId: primary._id,
|
|
621
|
-
projectId: args.projectId,
|
|
622
|
-
tenantId: inherited.tenantId,
|
|
623
|
-
workspaceId: inherited.workspaceId,
|
|
624
|
-
source: "project_mapped_topic"
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
const nodeScope = await resolveTopicNodeScopeOrNull(
|
|
628
|
-
ctx,
|
|
629
|
-
String(args.projectId)
|
|
630
|
-
);
|
|
631
|
-
if (nodeScope) {
|
|
632
|
-
return {
|
|
633
|
-
...nodeScope,
|
|
634
|
-
projectId: nodeScope.projectId ?? String(args.projectId)
|
|
635
|
-
};
|
|
636
|
-
}
|
|
637
|
-
throw new Error(
|
|
638
|
-
`Legacy project scope ${String(args.projectId)} has no mapped topic.`
|
|
639
|
-
);
|
|
581
|
+
return await resolveScopeFromLegacyProjectId(ctx, args.projectId);
|
|
640
582
|
}
|
|
641
583
|
throw new Error(
|
|
642
584
|
"Missing scope: provide topicId (preferred) or legacy projectId alias."
|
|
643
585
|
);
|
|
644
586
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
function normalizeScopeValue2(value) {
|
|
650
|
-
if (typeof value !== "string") {
|
|
651
|
-
return;
|
|
587
|
+
async function resolveScopeFromTopicId(ctx, topicId) {
|
|
588
|
+
const topic = await resolveTopicDocFromTopicId(ctx, topicId);
|
|
589
|
+
if (topic) {
|
|
590
|
+
return await buildTopicScope(ctx, topic, "topic");
|
|
652
591
|
}
|
|
653
|
-
const
|
|
654
|
-
|
|
592
|
+
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, String(topicId));
|
|
593
|
+
if (nodeScope) {
|
|
594
|
+
return nodeScope;
|
|
595
|
+
}
|
|
596
|
+
throw new Error(`Topic not found: ${String(topicId)}`);
|
|
655
597
|
}
|
|
656
|
-
function
|
|
657
|
-
|
|
658
|
-
|
|
598
|
+
async function resolveTopicDocFromTopicId(ctx, topicId) {
|
|
599
|
+
const direct = await tryReadTopicDoc(ctx, topicId, {
|
|
600
|
+
failureLog: "[topicScope] Failed to load topic by direct id",
|
|
601
|
+
idLogKey: "topicId"
|
|
602
|
+
});
|
|
603
|
+
if (direct) {
|
|
604
|
+
return direct;
|
|
659
605
|
}
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
const nodeWorkspaceId = normalizeScopeValue2(node.workspaceId);
|
|
664
|
-
const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
|
|
665
|
-
if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
|
|
666
|
-
return false;
|
|
606
|
+
const hostTopic = await tryResolveHostTopicById(ctx, String(topicId));
|
|
607
|
+
if (hostTopic) {
|
|
608
|
+
return hostTopic;
|
|
667
609
|
}
|
|
668
|
-
|
|
669
|
-
|
|
610
|
+
return pickPrimaryTopic(await findTopicsByScopeAlias(ctx, String(topicId))) ?? null;
|
|
611
|
+
}
|
|
612
|
+
async function resolveScopeFromLegacyProjectId(ctx, legacyProjectId) {
|
|
613
|
+
const directTopic = await resolveDirectLegacyProjectTopic(
|
|
614
|
+
ctx,
|
|
615
|
+
legacyProjectId
|
|
616
|
+
);
|
|
617
|
+
if (directTopic) {
|
|
618
|
+
return await buildTopicScope(ctx, directTopic, "topic_inferred", {
|
|
619
|
+
fallbackProjectId: legacyProjectId
|
|
620
|
+
});
|
|
670
621
|
}
|
|
671
|
-
|
|
672
|
-
|
|
622
|
+
const primary = pickPrimaryTopic(
|
|
623
|
+
await findTopicsByScopeAlias(ctx, legacyProjectId)
|
|
624
|
+
);
|
|
625
|
+
if (primary) {
|
|
626
|
+
return await buildTopicScope(ctx, primary, "project_mapped_topic", {
|
|
627
|
+
fallbackProjectId: legacyProjectId
|
|
628
|
+
});
|
|
673
629
|
}
|
|
674
|
-
|
|
675
|
-
|
|
630
|
+
const nodeScope = await resolveTopicNodeScopeOrNull(ctx, legacyProjectId);
|
|
631
|
+
if (nodeScope) {
|
|
632
|
+
return {
|
|
633
|
+
...nodeScope,
|
|
634
|
+
projectId: nodeScope.projectId ?? legacyProjectId
|
|
635
|
+
};
|
|
676
636
|
}
|
|
677
|
-
|
|
637
|
+
throw new Error(
|
|
638
|
+
`Legacy project scope ${legacyProjectId} has no mapped topic.`
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
async function resolveDirectLegacyProjectTopic(ctx, legacyProjectId) {
|
|
642
|
+
const directTopic = await tryReadTopicDoc(ctx, legacyProjectId, {
|
|
643
|
+
failureLog: "[topicScope] Failed to load direct project topic",
|
|
644
|
+
idLogKey: "projectId"
|
|
645
|
+
});
|
|
646
|
+
return directTopic ?? tryResolveHostTopicByLegacyScope(ctx, legacyProjectId);
|
|
678
647
|
}
|
|
648
|
+
async function tryReadTopicDoc(ctx, id, log) {
|
|
649
|
+
try {
|
|
650
|
+
return await ctx.db.get(id);
|
|
651
|
+
} catch (error) {
|
|
652
|
+
debugGraphPrimitiveFallback(log.failureLog, {
|
|
653
|
+
error,
|
|
654
|
+
[log.idLogKey]: id
|
|
655
|
+
});
|
|
656
|
+
return null;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
async function buildTopicScope(ctx, topic, source, options = {}) {
|
|
660
|
+
const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
|
|
661
|
+
const mapped = asMappedProjectId(topic);
|
|
662
|
+
return {
|
|
663
|
+
topicId: topic._id,
|
|
664
|
+
...mapped || options.fallbackProjectId ? { projectId: mapped ?? options.fallbackProjectId } : {},
|
|
665
|
+
tenantId: inherited.tenantId,
|
|
666
|
+
workspaceId: inherited.workspaceId,
|
|
667
|
+
source
|
|
668
|
+
};
|
|
669
|
+
}
|
|
670
|
+
var optionalScopeArgs = {
|
|
671
|
+
projectId: v.optional(v.string()),
|
|
672
|
+
topicId: v.optional(v.string())
|
|
673
|
+
};
|
|
679
674
|
|
|
680
675
|
// src/epistemicQuestions.helpers.ts
|
|
681
676
|
function normalizeCategory(category) {
|
|
@@ -728,7 +723,7 @@ function resolveQuestionScopeId(scope) {
|
|
|
728
723
|
return normalizeQuestionTopicId(scope.topicId) ?? scope.projectId ?? void 0;
|
|
729
724
|
}
|
|
730
725
|
async function resolveQuestionScopeOrNull(ctx, args) {
|
|
731
|
-
if (!args.projectId
|
|
726
|
+
if (!(args.projectId || args.topicId)) {
|
|
732
727
|
return null;
|
|
733
728
|
}
|
|
734
729
|
try {
|
|
@@ -784,7 +779,7 @@ function flattenQuestionNode(n) {
|
|
|
784
779
|
linkedBeliefId: meta.linkedBeliefNodeId || null,
|
|
785
780
|
testType: meta.testType || "validates",
|
|
786
781
|
importance: meta.importance || 5,
|
|
787
|
-
isKeyQuestion: meta.isKeyQuestion
|
|
782
|
+
isKeyQuestion: Boolean(meta.isKeyQuestion),
|
|
788
783
|
answer: meta.answer || null,
|
|
789
784
|
convictionStage: meta.convictionStage || null,
|
|
790
785
|
conviction: meta.conviction ?? null,
|
|
@@ -819,7 +814,7 @@ function getQuestionStatusCandidates(node) {
|
|
|
819
814
|
);
|
|
820
815
|
}
|
|
821
816
|
function isActiveQuestionNode(node) {
|
|
822
|
-
if (INACTIVE_NODE_STATUSES.has(node.status)) {
|
|
817
|
+
if (typeof node.status === "string" && INACTIVE_NODE_STATUSES.has(node.status)) {
|
|
823
818
|
return false;
|
|
824
819
|
}
|
|
825
820
|
return !getQuestionStatusCandidates(node).some(
|
|
@@ -832,8 +827,54 @@ function matchesRequestedQuestionStatus(node, requestedStatus) {
|
|
|
832
827
|
(status) => status.toLowerCase() === normalizedStatus
|
|
833
828
|
);
|
|
834
829
|
}
|
|
830
|
+
function normalizeScopeValue2(value) {
|
|
831
|
+
if (typeof value !== "string") {
|
|
832
|
+
return;
|
|
833
|
+
}
|
|
834
|
+
const normalized = value.trim();
|
|
835
|
+
return normalized.length > 0 ? normalized : void 0;
|
|
836
|
+
}
|
|
837
|
+
function nodeMatchesWorkspaceReasoningScope(node, scope) {
|
|
838
|
+
if (!node) {
|
|
839
|
+
return false;
|
|
840
|
+
}
|
|
841
|
+
const scopeTenantId = normalizeScopeValue2(scope.tenantId);
|
|
842
|
+
const scopeWorkspaceId = normalizeScopeValue2(scope.workspaceId);
|
|
843
|
+
const nodeTenantId = normalizeScopeValue2(node.tenantId);
|
|
844
|
+
const nodeWorkspaceId = normalizeScopeValue2(node.workspaceId);
|
|
845
|
+
const epistemicLayer = typeof node.epistemicLayer === "string" ? node.epistemicLayer : void 0;
|
|
846
|
+
if (scopeTenantId && nodeTenantId && scopeTenantId !== nodeTenantId) {
|
|
847
|
+
return false;
|
|
848
|
+
}
|
|
849
|
+
if (epistemicLayer === "ontological" && nodeWorkspaceId === void 0) {
|
|
850
|
+
return true;
|
|
851
|
+
}
|
|
852
|
+
if (!scopeWorkspaceId && node.publicationStatus === "published") {
|
|
853
|
+
return true;
|
|
854
|
+
}
|
|
855
|
+
if (!scopeWorkspaceId) {
|
|
856
|
+
return nodeWorkspaceId === void 0;
|
|
857
|
+
}
|
|
858
|
+
return scopeWorkspaceId === nodeWorkspaceId;
|
|
859
|
+
}
|
|
835
860
|
|
|
836
861
|
// src/epistemicQuestions.queries.ts
|
|
862
|
+
function readOptionalString(value) {
|
|
863
|
+
return typeof value === "string" && value.trim().length > 0 ? value : void 0;
|
|
864
|
+
}
|
|
865
|
+
function readConvexId(value) {
|
|
866
|
+
const normalized = readOptionalString(value);
|
|
867
|
+
return normalized ? normalized : null;
|
|
868
|
+
}
|
|
869
|
+
function readRecord(value) {
|
|
870
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
871
|
+
}
|
|
872
|
+
function readEdgeQuestionEndpoint(edge, endpoint) {
|
|
873
|
+
return readConvexId(readRecord(edge)[endpoint]);
|
|
874
|
+
}
|
|
875
|
+
function isQuestionNodeDoc(value) {
|
|
876
|
+
return readRecord(value).nodeType === "question";
|
|
877
|
+
}
|
|
837
878
|
var getById = query({
|
|
838
879
|
args: {
|
|
839
880
|
nodeId: v.optional(v.id("epistemicNodes")),
|
|
@@ -841,14 +882,12 @@ var getById = query({
|
|
|
841
882
|
},
|
|
842
883
|
returns: permissiveReturn,
|
|
843
884
|
handler: async (ctx, args) => {
|
|
844
|
-
const id = args.nodeId ?? args.questionId;
|
|
885
|
+
const id = args.nodeId ?? readConvexId(args.questionId);
|
|
845
886
|
if (!id) {
|
|
846
887
|
return null;
|
|
847
888
|
}
|
|
848
|
-
const node = await ctx.db.get(
|
|
849
|
-
|
|
850
|
-
);
|
|
851
|
-
if (!node || node.nodeType !== "question") {
|
|
889
|
+
const node = await ctx.db.get(id);
|
|
890
|
+
if (!isQuestionNodeDoc(node)) {
|
|
852
891
|
return null;
|
|
853
892
|
}
|
|
854
893
|
return flattenQuestionNode(node);
|
|
@@ -882,8 +921,9 @@ var getByProject = query({
|
|
|
882
921
|
const workspaceScopedNodes = await getQuestionNodesForScope(ctx, scope, {
|
|
883
922
|
scanLimit
|
|
884
923
|
});
|
|
885
|
-
const
|
|
886
|
-
|
|
924
|
+
const requestedStatus = args.status;
|
|
925
|
+
const scopedNodes = requestedStatus ? workspaceScopedNodes.filter(
|
|
926
|
+
(node) => matchesRequestedQuestionStatus(node, requestedStatus)
|
|
887
927
|
) : workspaceScopedNodes.filter(isActiveQuestionNode);
|
|
888
928
|
return scopedNodes.map(flattenQuestionNode).slice(0, pageSize);
|
|
889
929
|
}
|
|
@@ -905,8 +945,9 @@ var getByTopic = query({
|
|
|
905
945
|
const scopedNodes = await getQuestionNodesForScope(ctx, scope, {
|
|
906
946
|
scanLimit
|
|
907
947
|
});
|
|
908
|
-
const
|
|
909
|
-
|
|
948
|
+
const requestedStatus = args.status;
|
|
949
|
+
const filteredNodes = requestedStatus ? scopedNodes.filter(
|
|
950
|
+
(node) => matchesRequestedQuestionStatus(node, requestedStatus)
|
|
910
951
|
) : scopedNodes.filter(isActiveQuestionNode);
|
|
911
952
|
return filteredNodes.map(flattenQuestionNode).slice(0, pageSize);
|
|
912
953
|
}
|
|
@@ -935,16 +976,34 @@ var getForBelief = query({
|
|
|
935
976
|
},
|
|
936
977
|
returns: permissiveReturn,
|
|
937
978
|
handler: async (ctx, args) => {
|
|
938
|
-
const
|
|
939
|
-
"
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
979
|
+
const [canonicalEdges, legacyEdges] = await Promise.all([
|
|
980
|
+
ctx.db.query("epistemicEdges").withIndex(
|
|
981
|
+
"by_to_type",
|
|
982
|
+
(q) => q.eq("toNodeId", args.beliefNodeId).eq("edgeType", "tests")
|
|
983
|
+
).collect(),
|
|
984
|
+
ctx.db.query("epistemicEdges").withIndex(
|
|
985
|
+
"by_from_type",
|
|
986
|
+
(q) => q.eq("fromNodeId", args.beliefNodeId).eq("edgeType", "tests")
|
|
987
|
+
).collect()
|
|
988
|
+
]);
|
|
989
|
+
const questionNodeIds = /* @__PURE__ */ new Set();
|
|
990
|
+
for (const edge of canonicalEdges) {
|
|
991
|
+
const questionId = readEdgeQuestionEndpoint(edge, "fromNodeId");
|
|
992
|
+
if (questionId) {
|
|
993
|
+
questionNodeIds.add(questionId);
|
|
994
|
+
}
|
|
995
|
+
}
|
|
996
|
+
for (const edge of legacyEdges) {
|
|
997
|
+
const questionId = readEdgeQuestionEndpoint(edge, "toNodeId");
|
|
998
|
+
if (questionId) {
|
|
999
|
+
questionNodeIds.add(questionId);
|
|
1000
|
+
}
|
|
1001
|
+
}
|
|
943
1002
|
const questions = await Promise.all(
|
|
944
|
-
questionNodeIds.map((id) => ctx.db.get(id))
|
|
1003
|
+
[...questionNodeIds].map((id) => ctx.db.get(id))
|
|
945
1004
|
);
|
|
946
1005
|
return questions.filter(
|
|
947
|
-
(q) => q
|
|
1006
|
+
(q) => isQuestionNodeDoc(q) && isActiveQuestionNode(q)
|
|
948
1007
|
);
|
|
949
1008
|
}
|
|
950
1009
|
});
|
|
@@ -1003,8 +1062,9 @@ var internalGetByProject = internalQuery({
|
|
|
1003
1062
|
resolveAudienceClass(node.audienceLabel, "internal")
|
|
1004
1063
|
)
|
|
1005
1064
|
);
|
|
1006
|
-
const
|
|
1007
|
-
|
|
1065
|
+
const requestedStatus = args.status;
|
|
1066
|
+
const scopedNodes = requestedStatus ? visibleNodes.filter(
|
|
1067
|
+
(node) => matchesRequestedQuestionStatus(node, requestedStatus)
|
|
1008
1068
|
) : visibleNodes.filter(isActiveQuestionNode);
|
|
1009
1069
|
return scopedNodes.slice(0, pageSize).map(flattenInternalQuestionNode);
|
|
1010
1070
|
}
|
|
@@ -1055,8 +1115,9 @@ var internalGetByTopic = internalQuery({
|
|
|
1055
1115
|
resolveAudienceClass(node.audienceLabel, "internal")
|
|
1056
1116
|
)
|
|
1057
1117
|
);
|
|
1058
|
-
const
|
|
1059
|
-
|
|
1118
|
+
const requestedStatus = args.status;
|
|
1119
|
+
const scopedNodes = requestedStatus ? visibleNodes.filter(
|
|
1120
|
+
(node) => matchesRequestedQuestionStatus(node, requestedStatus)
|
|
1060
1121
|
) : visibleNodes.filter(isActiveQuestionNode);
|
|
1061
1122
|
return scopedNodes.slice(0, pageSize).map(flattenInternalQuestionNode);
|
|
1062
1123
|
}
|