@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.
Files changed (319) hide show
  1. package/dist/{beliefDecay-DZ6tkLYq.d.ts → beliefDecay-BmkEk5OJ.d.ts} +3 -3
  2. package/dist/beliefDecay.d.ts +1 -1
  3. package/dist/beliefDecay.js +448 -314
  4. package/dist/beliefDecay.js.map +1 -1
  5. package/dist/{beliefEvidenceLinks-CWOXxxJg.d.ts → beliefEvidenceLinks-BzfjON_6.d.ts} +13 -13
  6. package/dist/beliefEvidenceLinks.d.ts +1 -1
  7. package/dist/beliefEvidenceLinks.js +843 -624
  8. package/dist/beliefEvidenceLinks.js.map +1 -1
  9. package/dist/beliefEvidenceLinks.operational.d.ts +7 -5
  10. package/dist/beliefEvidenceLinks.operational.js +91 -18
  11. package/dist/beliefEvidenceLinks.operational.js.map +1 -1
  12. package/dist/beliefLifecycle.js.map +1 -1
  13. package/dist/confidencePropagationDispatch.d.ts +28 -27
  14. package/dist/confidencePropagationDispatch.js +157 -99
  15. package/dist/confidencePropagationDispatch.js.map +1 -1
  16. package/dist/{contradictions-51VLsESq.d.ts → contradictions-BATPuZTL.d.ts} +10 -10
  17. package/dist/contradictions.d.ts +1 -1
  18. package/dist/contradictions.js +398 -228
  19. package/dist/contradictions.js.map +1 -1
  20. package/dist/convex.d.ts +65 -30
  21. package/dist/convex.js +7 -3
  22. package/dist/convex.js.map +1 -1
  23. package/dist/debug.js.map +1 -1
  24. package/dist/edgeValidation.js +293 -85
  25. package/dist/edgeValidation.js.map +1 -1
  26. package/dist/edges/contains.d.ts +1 -1
  27. package/dist/edges/contains.js.map +1 -1
  28. package/dist/edges/contradicts.d.ts +1 -1
  29. package/dist/edges/contradicts.js.map +1 -1
  30. package/dist/edges/{dependsOn.d.ts → depends-on.d.ts} +1 -1
  31. package/dist/edges/{dependsOn.js → depends-on.js} +4 -4
  32. package/dist/edges/depends-on.js.map +1 -0
  33. package/dist/edges/{derivedFrom.d.ts → derived-from.d.ts} +1 -1
  34. package/dist/edges/{derivedFrom.js → derived-from.js} +3 -3
  35. package/dist/edges/derived-from.js.map +1 -0
  36. package/dist/edges/elaborates.d.ts +1 -1
  37. package/dist/edges/elaborates.js.map +1 -1
  38. package/dist/edges/index.d.ts +7 -3
  39. package/dist/edges/index.js +7 -4
  40. package/dist/edges/index.js.map +1 -1
  41. package/dist/edges/informs.d.ts +1 -1
  42. package/dist/edges/informs.js.map +1 -1
  43. package/dist/edges/{propagationTypes.d.ts → propagation-types.d.ts} +14 -14
  44. package/dist/edges/{propagationTypes.js → propagation-types.js} +3 -3
  45. package/dist/edges/propagation-types.js.map +1 -0
  46. package/dist/edges/refutes.d.ts +1 -1
  47. package/dist/edges/refutes.js.map +1 -1
  48. package/dist/edges/supports.d.ts +1 -1
  49. package/dist/edges/supports.js.map +1 -1
  50. package/dist/edges/tests.d.ts +1 -1
  51. package/dist/edges/tests.js.map +1 -1
  52. package/dist/edges/utils.d.ts +1 -1
  53. package/dist/edges/utils.js.map +1 -1
  54. package/dist/embeddingTrigger.d.ts +14 -6
  55. package/dist/embeddingTrigger.js +11 -14
  56. package/dist/embeddingTrigger.js.map +1 -1
  57. package/dist/{entityBridge-DMaKooYn.d.ts → entityBridge-BhVDM3pc.d.ts} +5 -5
  58. package/dist/entityBridge.d.ts +1 -1
  59. package/dist/entityBridge.js +602 -225
  60. package/dist/entityBridge.js.map +1 -1
  61. package/dist/entityCanonicalMatch.d.ts +14 -12
  62. package/dist/entityCanonicalMatch.js.map +1 -1
  63. package/dist/{entityLifecycle-CvgSK5FV.d.ts → entityLifecycle-BsfCz9pS.d.ts} +5 -9
  64. package/dist/entityLifecycle.d.ts +1 -1
  65. package/dist/entityLifecycle.js +857 -515
  66. package/dist/entityLifecycle.js.map +1 -1
  67. package/dist/{entityValidation-KLZ_Xl2D.d.ts → entityValidation-B1yNEHJx.d.ts} +7 -6
  68. package/dist/entityValidation.d.ts +3 -1
  69. package/dist/entityValidation.js +60 -8
  70. package/dist/entityValidation.js.map +1 -1
  71. package/dist/{epistemicAnswers-C5ib4z6_.d.ts → epistemicAnswers-f47YMu9U.d.ts} +6 -6
  72. package/dist/epistemicAnswers.d.ts +1 -1
  73. package/dist/epistemicAnswers.js +587 -545
  74. package/dist/epistemicAnswers.js.map +1 -1
  75. package/dist/epistemicBeliefs.admin.d.ts +8 -8
  76. package/dist/epistemicBeliefs.admin.js +366 -203
  77. package/dist/epistemicBeliefs.admin.js.map +1 -1
  78. package/dist/epistemicBeliefs.backfills.d.ts +8 -8
  79. package/dist/epistemicBeliefs.backfills.js +655 -308
  80. package/dist/epistemicBeliefs.backfills.js.map +1 -1
  81. package/dist/epistemicBeliefs.confidence.d.ts +19 -14
  82. package/dist/epistemicBeliefs.confidence.js +634 -423
  83. package/dist/epistemicBeliefs.confidence.js.map +1 -1
  84. package/dist/epistemicBeliefs.core.d.ts +6 -6
  85. package/dist/epistemicBeliefs.core.js +719 -411
  86. package/dist/epistemicBeliefs.core.js.map +1 -1
  87. package/dist/epistemicBeliefs.d.ts +11 -8
  88. package/dist/epistemicBeliefs.forkEvidence.d.ts +2 -0
  89. package/dist/epistemicBeliefs.forkEvidence.js +8 -28
  90. package/dist/epistemicBeliefs.forkEvidence.js.map +1 -1
  91. package/dist/epistemicBeliefs.helpers.d.ts +69 -74
  92. package/dist/epistemicBeliefs.helpers.js +359 -248
  93. package/dist/epistemicBeliefs.helpers.js.map +1 -1
  94. package/dist/epistemicBeliefs.internal.d.ts +5 -5
  95. package/dist/epistemicBeliefs.internal.js +1246 -1044
  96. package/dist/epistemicBeliefs.internal.js.map +1 -1
  97. package/dist/epistemicBeliefs.js +4922 -3608
  98. package/dist/epistemicBeliefs.js.map +1 -1
  99. package/dist/epistemicBeliefs.lifecycle.d.ts +5 -5
  100. package/dist/epistemicBeliefs.lifecycle.js +1137 -818
  101. package/dist/epistemicBeliefs.lifecycle.js.map +1 -1
  102. package/dist/epistemicBeliefs.links.d.ts +7 -7
  103. package/dist/epistemicBeliefs.links.js +408 -307
  104. package/dist/epistemicBeliefs.links.js.map +1 -1
  105. package/dist/epistemicBeliefs.queries.d.ts +4 -4
  106. package/dist/epistemicBeliefs.queries.js +175 -20
  107. package/dist/epistemicBeliefs.queries.js.map +1 -1
  108. package/dist/epistemicBeliefs.topicAnchor.d.ts +6 -4
  109. package/dist/epistemicBeliefs.topicAnchor.js +12 -5
  110. package/dist/epistemicBeliefs.topicAnchor.js.map +1 -1
  111. package/dist/epistemicContracts.d.ts +28 -3
  112. package/dist/epistemicContracts.evaluators.d.ts +2 -0
  113. package/dist/epistemicContracts.evaluators.js +1063 -613
  114. package/dist/epistemicContracts.evaluators.js.map +1 -1
  115. package/dist/epistemicContracts.handlers.d.ts +15 -32
  116. package/dist/epistemicContracts.handlers.js +2086 -1644
  117. package/dist/epistemicContracts.handlers.js.map +1 -1
  118. package/dist/epistemicContracts.js +1131 -672
  119. package/dist/epistemicContracts.js.map +1 -1
  120. package/dist/epistemicContracts.metrics.d.ts +2 -0
  121. package/dist/epistemicContracts.metrics.js +375 -158
  122. package/dist/epistemicContracts.metrics.js.map +1 -1
  123. package/dist/epistemicContracts.types.d.ts +87 -81
  124. package/dist/epistemicEdgeCreation.d.ts +2 -0
  125. package/dist/epistemicEdgeCreation.js +87 -16
  126. package/dist/epistemicEdgeCreation.js.map +1 -1
  127. package/dist/{epistemicEdges-BF-cn4i3.d.ts → epistemicEdges-BGBh0QSP.d.ts} +4 -7
  128. package/dist/epistemicEdges.d.ts +6 -5
  129. package/dist/epistemicEdges.handlers.d.ts +3 -3
  130. package/dist/epistemicEdges.handlers.js +129 -24
  131. package/dist/epistemicEdges.handlers.js.map +1 -1
  132. package/dist/epistemicEdges.helpers.d.ts +6 -4
  133. package/dist/epistemicEdges.helpers.js +37 -2
  134. package/dist/epistemicEdges.helpers.js.map +1 -1
  135. package/dist/epistemicEdges.js +1969 -1205
  136. package/dist/epistemicEdges.js.map +1 -1
  137. package/dist/epistemicEdges.mutations.d.ts +7 -7
  138. package/dist/epistemicEdges.mutations.js +960 -583
  139. package/dist/epistemicEdges.mutations.js.map +1 -1
  140. package/dist/epistemicEdges.queries.d.ts +16 -16
  141. package/dist/epistemicEdges.queries.js +639 -367
  142. package/dist/epistemicEdges.queries.js.map +1 -1
  143. package/dist/epistemicEdges.types.d.ts +10 -8
  144. package/dist/epistemicEvidence.d.ts +4 -1
  145. package/dist/epistemicEvidence.js +937 -536
  146. package/dist/epistemicEvidence.js.map +1 -1
  147. package/dist/epistemicEvidenceHelpers.d.ts +26 -10
  148. package/dist/epistemicEvidenceHelpers.js +239 -200
  149. package/dist/epistemicEvidenceHelpers.js.map +1 -1
  150. package/dist/epistemicEvidenceMutations.d.ts +8 -8
  151. package/dist/epistemicEvidenceMutations.js +844 -696
  152. package/dist/epistemicEvidenceMutations.js.map +1 -1
  153. package/dist/epistemicEvidenceQueries.d.ts +8 -8
  154. package/dist/epistemicEvidenceQueries.js +514 -238
  155. package/dist/epistemicEvidenceQueries.js.map +1 -1
  156. package/dist/epistemicHelpers.d.ts +4 -2
  157. package/dist/epistemicHelpers.js +308 -134
  158. package/dist/epistemicHelpers.js.map +1 -1
  159. package/dist/epistemicInsert.d.ts +16 -4
  160. package/dist/epistemicInsert.js +6 -3
  161. package/dist/epistemicInsert.js.map +1 -1
  162. package/dist/epistemicLayerRules.d.ts +10 -8
  163. package/dist/epistemicLayerRules.js +1 -5
  164. package/dist/epistemicLayerRules.js.map +1 -1
  165. package/dist/{epistemicLinking-CfE00tHJ.d.ts → epistemicLinking-CsCDv2cN.d.ts} +3 -3
  166. package/dist/epistemicLinking.d.ts +1 -1
  167. package/dist/epistemicLinking.js +177 -100
  168. package/dist/epistemicLinking.js.map +1 -1
  169. package/dist/epistemicNodeCreation.d.ts +2 -0
  170. package/dist/epistemicNodeCreation.js +203 -40
  171. package/dist/epistemicNodeCreation.js.map +1 -1
  172. package/dist/{epistemicNodes-BCQxpYx_.d.ts → epistemicNodes-CokAgBHg.d.ts} +3 -3
  173. package/dist/epistemicNodes.d.ts +3 -3
  174. package/dist/epistemicNodes.helpers.d.ts +24 -15
  175. package/dist/epistemicNodes.helpers.js.map +1 -1
  176. package/dist/epistemicNodes.internal.d.ts +6 -6
  177. package/dist/epistemicNodes.internal.js +389 -319
  178. package/dist/epistemicNodes.internal.js.map +1 -1
  179. package/dist/epistemicNodes.js +704 -508
  180. package/dist/epistemicNodes.js.map +1 -1
  181. package/dist/epistemicNodes.mutations.d.ts +6 -6
  182. package/dist/epistemicNodes.mutations.js +564 -467
  183. package/dist/epistemicNodes.mutations.js.map +1 -1
  184. package/dist/epistemicNodes.queries.d.ts +8 -8
  185. package/dist/epistemicNodes.queries.js +311 -314
  186. package/dist/epistemicNodes.queries.js.map +1 -1
  187. package/dist/epistemicNodes.validators.d.ts +2 -2
  188. package/dist/epistemicNodes.validators.js.map +1 -1
  189. package/dist/epistemicQuestions.conviction.d.ts +8 -8
  190. package/dist/epistemicQuestions.conviction.js +665 -484
  191. package/dist/epistemicQuestions.conviction.js.map +1 -1
  192. package/dist/epistemicQuestions.create.d.ts +4 -4
  193. package/dist/epistemicQuestions.create.js +640 -612
  194. package/dist/epistemicQuestions.create.js.map +1 -1
  195. package/dist/epistemicQuestions.d.ts +8 -5
  196. package/dist/epistemicQuestions.evidence.d.ts +2 -2
  197. package/dist/epistemicQuestions.evidence.js +475 -383
  198. package/dist/epistemicQuestions.evidence.js.map +1 -1
  199. package/dist/epistemicQuestions.helpers.d.ts +125 -24
  200. package/dist/epistemicQuestions.helpers.js +240 -209
  201. package/dist/epistemicQuestions.helpers.js.map +1 -1
  202. package/dist/epistemicQuestions.js +3474 -2823
  203. package/dist/epistemicQuestions.js.map +1 -1
  204. package/dist/epistemicQuestions.lifecycle.d.ts +2 -2
  205. package/dist/epistemicQuestions.lifecycle.js +607 -546
  206. package/dist/epistemicQuestions.lifecycle.js.map +1 -1
  207. package/dist/epistemicQuestions.queries.d.ts +12 -7
  208. package/dist/epistemicQuestions.queries.js +305 -244
  209. package/dist/epistemicQuestions.queries.js.map +1 -1
  210. package/dist/epistemicQuestions.sprint.d.ts +2 -2
  211. package/dist/epistemicQuestions.sprint.js +600 -394
  212. package/dist/epistemicQuestions.sprint.js.map +1 -1
  213. package/dist/epistemicQuestions.tail.d.ts +6 -6
  214. package/dist/epistemicQuestions.tail.js +572 -433
  215. package/dist/epistemicQuestions.tail.js.map +1 -1
  216. package/dist/{epistemicSources-dlKj58Jp.d.ts → epistemicSources-DQtaEkWs.d.ts} +4 -4
  217. package/dist/epistemicSources.d.ts +1 -1
  218. package/dist/epistemicSources.js +352 -312
  219. package/dist/epistemicSources.js.map +1 -1
  220. package/dist/evaluators/index.d.ts +8 -6
  221. package/dist/evaluators/index.js +399 -167
  222. package/dist/evaluators/index.js.map +1 -1
  223. package/dist/evaluators/lint-checker-evaluator.d.ts +16 -0
  224. package/dist/evaluators/{lintCheckerEvaluator.js → lint-checker-evaluator.js} +10 -5
  225. package/dist/evaluators/lint-checker-evaluator.js.map +1 -0
  226. package/dist/evaluators/{sentryCheckerEvaluator.d.ts → sentry-checker-evaluator.d.ts} +7 -2
  227. package/dist/evaluators/{sentryCheckerEvaluator.js → sentry-checker-evaluator.js} +3 -3
  228. package/dist/evaluators/sentry-checker-evaluator.js.map +1 -0
  229. package/dist/evaluators/shared.d.ts +2 -2
  230. package/dist/evaluators/shared.js +3 -1
  231. package/dist/evaluators/shared.js.map +1 -1
  232. package/dist/evaluators/{testRunnerEvaluator.d.ts → test-runner-evaluator.d.ts} +6 -1
  233. package/dist/evaluators/{testRunnerEvaluator.js → test-runner-evaluator.js} +6 -4
  234. package/dist/evaluators/test-runner-evaluator.js.map +1 -0
  235. package/dist/evaluators/tsc-checker-evaluator.d.ts +16 -0
  236. package/dist/evaluators/{tscCheckerEvaluator.js → tsc-checker-evaluator.js} +10 -5
  237. package/dist/evaluators/tsc-checker-evaluator.js.map +1 -0
  238. package/dist/graphTypes.js +6 -2
  239. package/dist/graphTypes.js.map +1 -1
  240. package/dist/helpers.d.ts +2 -0
  241. package/dist/helpers.js +313 -93
  242. package/dist/helpers.js.map +1 -1
  243. package/dist/{index-C-Kyd7hD.d.ts → index-DZxyC9Pb.d.ts} +7 -6
  244. package/dist/index.d.ts +87 -83
  245. package/dist/index.js +15677 -10594
  246. package/dist/index.js.map +1 -1
  247. package/dist/invariantEnforcement.d.ts +3 -3
  248. package/dist/invariantEnforcement.js.map +1 -1
  249. package/dist/logicalRoleInference.d.ts +2 -0
  250. package/dist/logicalRoleInference.js +1 -1
  251. package/dist/logicalRoleInference.js.map +1 -1
  252. package/dist/matcherFeedbackUtils.d.ts +2 -2
  253. package/dist/matcherFeedbackUtils.js.map +1 -1
  254. package/dist/{ontology-matching-C6rrz2VP.d.ts → ontology-matching-C-mYFrir.d.ts} +16 -16
  255. package/dist/ontology-matching.d.ts +1 -1
  256. package/dist/{ontologyApproval-CFYmqKmk.d.ts → ontologyApproval-BVt0feJi.d.ts} +10 -10
  257. package/dist/ontologyApproval.d.ts +1 -1
  258. package/dist/ontologyApproval.js +7 -1
  259. package/dist/ontologyApproval.js.map +1 -1
  260. package/dist/ontologyDefinitions.d.ts +14 -24
  261. package/dist/ontologyDefinitions.js +269 -34
  262. package/dist/ontologyDefinitions.js.map +1 -1
  263. package/dist/ontologyHelpers.d.ts +13 -13
  264. package/dist/ontologyHelpers.js.map +1 -1
  265. package/dist/{ontologyRegistry-B67rPJ16.d.ts → ontologyRegistry-CljS-ENv.d.ts} +2 -2
  266. package/dist/ontologyRegistry.d.ts +1 -1
  267. package/dist/ontologyRegistry.js +34 -6
  268. package/dist/ontologyRegistry.js.map +1 -1
  269. package/dist/{projectionReconciliation-jww2fBI0.d.ts → projectionReconciliation-DnrSgHSQ.d.ts} +4 -4
  270. package/dist/projectionReconciliation.d.ts +1 -1
  271. package/dist/projectionReconciliation.js +57 -10
  272. package/dist/projectionReconciliation.js.map +1 -1
  273. package/dist/{projectionStaleness-CmdbpjVK.d.ts → projectionStaleness-C8ImQ2zP.d.ts} +17 -17
  274. package/dist/projectionStaleness.d.ts +1 -1
  275. package/dist/projectionStaleness.js +8 -2
  276. package/dist/projectionStaleness.js.map +1 -1
  277. package/dist/proof-attestation.json +1 -1
  278. package/dist/{questionEvidenceLinks-DFlyPpAj.d.ts → questionEvidenceLinks-_nPRa-LY.d.ts} +10 -10
  279. package/dist/questionEvidenceLinks.d.ts +1 -1
  280. package/dist/questionEvidenceLinks.js +564 -347
  281. package/dist/questionEvidenceLinks.js.map +1 -1
  282. package/dist/{resolverTypes-CC8Ea2E2.d.ts → resolverTypes-BOXPxLET.d.ts} +8 -7
  283. package/dist/resolverTypes.d.ts +4 -2
  284. package/dist/{resolvers-Br1a6eLV.d.ts → resolvers-B1TIBmRO.d.ts} +3 -1
  285. package/dist/resolvers.d.ts +5 -3
  286. package/dist/resolvers.js +121 -77
  287. package/dist/resolvers.js.map +1 -1
  288. package/dist/scopeResolverCompat.d.ts +10 -7
  289. package/dist/scopeResolverCompat.js +106 -123
  290. package/dist/scopeResolverCompat.js.map +1 -1
  291. package/dist/{text-matching-DNg4M5Wd.d.ts → text-matching-DzFooju6.d.ts} +7 -7
  292. package/dist/text-matching.d.ts +1 -1
  293. package/dist/topicOntologyResolver.d.ts +22 -21
  294. package/dist/topicOntologyResolver.js +54 -32
  295. package/dist/topicOntologyResolver.js.map +1 -1
  296. package/dist/topicProjectOverlay.d.ts +30 -20
  297. package/dist/topicProjectOverlay.js +120 -76
  298. package/dist/topicProjectOverlay.js.map +1 -1
  299. package/dist/{topicScope-7zhyeGl7.d.ts → topicScope-DJVa0mLa.d.ts} +22 -7
  300. package/dist/topicScope.d.ts +3 -1
  301. package/dist/topicScope.js +104 -119
  302. package/dist/topicScope.js.map +1 -1
  303. package/dist/workflowBridge.d.ts +26 -15
  304. package/dist/workflowBridge.js +140 -144
  305. package/dist/workflowBridge.js.map +1 -1
  306. package/dist/workspaceIsolation.d.ts +14 -12
  307. package/dist/workspaceIsolation.js +108 -122
  308. package/dist/workspaceIsolation.js.map +1 -1
  309. package/package.json +4 -4
  310. package/dist/edges/dependsOn.js.map +0 -1
  311. package/dist/edges/derivedFrom.js.map +0 -1
  312. package/dist/edges/propagationTypes.js.map +0 -1
  313. package/dist/evaluators/lintCheckerEvaluator.d.ts +0 -11
  314. package/dist/evaluators/lintCheckerEvaluator.js.map +0 -1
  315. package/dist/evaluators/sentryCheckerEvaluator.js.map +0 -1
  316. package/dist/evaluators/testRunnerEvaluator.js.map +0 -1
  317. package/dist/evaluators/tscCheckerEvaluator.d.ts +0 -11
  318. package/dist/evaluators/tscCheckerEvaluator.js.map +0 -1
  319. package/dist/{epistemicQuestions-bwHd2FWE.d.ts → epistemicQuestions-Do1fhYm5.d.ts} +4 -4
@@ -1,10 +1,14 @@
1
- import { componentsGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric, anyApi } from 'convex/server';
1
+ import { unsafeConvexAnyApi } from '@lucern/contracts/convex/unsafeAnyApi';
2
+ import { componentsGeneric, internalMutationGeneric, internalQueryGeneric, mutationGeneric, queryGeneric } from 'convex/server';
2
3
  import { v } from 'convex/values';
3
4
 
4
5
  // src/convex.ts
5
- var api = anyApi;
6
+ var unsafeApi = unsafeConvexAnyApi(
7
+ "graph-primitives top-level module bundle lacks a committed Convex _generated/api surface"
8
+ );
9
+ var api = unsafeApi;
6
10
  componentsGeneric();
7
- var internal = anyApi;
11
+ var internal = unsafeApi;
8
12
  var internalMutation = internalMutationGeneric;
9
13
  var internalQuery = internalQueryGeneric;
10
14
  var mutation = mutationGeneric;
@@ -59,6 +63,10 @@ function readStringArray(value) {
59
63
  function readMetadata(topic) {
60
64
  return topic.metadata && typeof topic.metadata === "object" ? topic.metadata : {};
61
65
  }
66
+ function omitMetadataKey(metadata, key) {
67
+ const { [key]: _omitted, ...rest } = metadata;
68
+ return rest;
69
+ }
62
70
  function readLegacyProjectId(value) {
63
71
  if (!value) {
64
72
  return;
@@ -139,9 +147,12 @@ async function resolveTopicDoc(ctx, scopeId) {
139
147
  );
140
148
  }
141
149
  try {
142
- const topic = await ctx.runQuery(api.topics.getByLegacyScopeId, {
143
- projectId: String(scopeId)
144
- });
150
+ const topic = await ctx.runQuery(
151
+ api.topics.getByLegacyScopeId,
152
+ {
153
+ projectId: String(scopeId)
154
+ }
155
+ );
145
156
  if (topic?.name !== void 0 && topic?.type !== void 0) {
146
157
  return topic;
147
158
  }
@@ -161,8 +172,18 @@ function materializeTopicProjectOverlay(topic, idMode = "legacy") {
161
172
  const outwardId = idMode === "topic" ? topicId : storageProjectId;
162
173
  const visibility = coerceVisibility(topic.visibility) || coerceVisibility(metadata.visibility) || "private";
163
174
  const status = coerceStatus(topic.status) || coerceStatus(metadata.status) || "active";
164
- const createdAt = typeof topic.createdAt === "number" ? topic.createdAt : typeof topic._creationTime === "number" ? topic._creationTime : 0;
165
- const updatedAt = typeof topic.updatedAt === "number" ? topic.updatedAt : typeof metadata.updatedAt === "number" ? metadata.updatedAt : createdAt;
175
+ let createdAt = 0;
176
+ if (typeof topic.createdAt === "number") {
177
+ createdAt = topic.createdAt;
178
+ } else if (typeof topic._creationTime === "number") {
179
+ createdAt = topic._creationTime;
180
+ }
181
+ let updatedAt = createdAt;
182
+ if (typeof topic.updatedAt === "number") {
183
+ updatedAt = topic.updatedAt;
184
+ } else if (typeof metadata.updatedAt === "number") {
185
+ updatedAt = metadata.updatedAt;
186
+ }
166
187
  return {
167
188
  ...metadata,
168
189
  _id: outwardId,
@@ -231,90 +252,113 @@ async function patchTopicProjectOverlay(ctx, scopeId, value) {
231
252
  if (!topic) {
232
253
  return null;
233
254
  }
234
- const nextMetadata = { ...readMetadata(topic) };
235
- const patch = {};
236
- const topicUpdateArgs = {
237
- id: String(topic._id)
255
+ const plan = buildTopicProjectOverlayPatchPlan(topic, value);
256
+ await applyTopicProjectOverlayPatch(ctx, topic, plan);
257
+ return materializeTopicProjectOverlay({
258
+ ...topic,
259
+ ...plan.patch,
260
+ metadata: plan.nextMetadata
261
+ });
262
+ }
263
+ function buildTopicProjectOverlayPatchPlan(topic, value) {
264
+ const plan = {
265
+ nextMetadata: { ...readMetadata(topic) },
266
+ patch: {},
267
+ topicUpdateArgs: {
268
+ id: String(topic._id)
269
+ }
238
270
  };
239
271
  for (const [key, rawValue] of Object.entries(value)) {
240
- switch (key) {
241
- case "_id":
242
- case "projectId":
243
- case "topicId":
244
- case "legacyProjectId":
245
- case "storageProjectId":
246
- break;
247
- case "name":
248
- case "description":
249
- patch[key] = rawValue;
250
- topicUpdateArgs[key] = rawValue;
251
- break;
252
- case "tenantId":
253
- case "workspaceId":
254
- case "ownerId":
255
- throw new Error(
256
- `patchTopicProjectOverlay cannot mutate ${key} via component-owned topics`
257
- );
258
- case "status": {
259
- const status = coerceStatus(rawValue);
260
- if (status) {
261
- patch.status = status;
262
- topicUpdateArgs.status = status;
263
- }
264
- break;
265
- }
266
- case "visibility": {
267
- const visibility = coerceVisibility(rawValue);
268
- if (visibility) {
269
- patch.visibility = visibility;
270
- topicUpdateArgs.visibility = visibility;
271
- }
272
- break;
273
- }
274
- case "type": {
275
- const projectType = readNonEmptyString(rawValue);
276
- if (projectType) {
277
- nextMetadata.projectType = projectType;
278
- } else {
279
- delete nextMetadata.projectType;
280
- }
281
- break;
282
- }
283
- case "updatedAt":
284
- case "createdAt":
285
- break;
286
- default:
287
- if (rawValue === void 0) {
288
- delete nextMetadata[key];
289
- } else {
290
- nextMetadata[key] = rawValue;
291
- }
292
- }
272
+ applyTopicProjectOverlayPatchEntry(plan, key, rawValue);
273
+ }
274
+ plan.patch.updatedAt = Date.now();
275
+ plan.patch.metadata = plan.nextMetadata;
276
+ plan.topicUpdateArgs.metadata = plan.nextMetadata;
277
+ return plan;
278
+ }
279
+ function applyTopicProjectOverlayPatchEntry(plan, key, rawValue) {
280
+ switch (key) {
281
+ case "_id":
282
+ case "projectId":
283
+ case "topicId":
284
+ case "legacyProjectId":
285
+ case "storageProjectId":
286
+ case "updatedAt":
287
+ case "createdAt":
288
+ return;
289
+ case "name":
290
+ case "description":
291
+ plan.patch[key] = rawValue;
292
+ plan.topicUpdateArgs[key] = rawValue;
293
+ return;
294
+ case "tenantId":
295
+ case "workspaceId":
296
+ case "ownerId":
297
+ throw new Error(
298
+ `patchTopicProjectOverlay cannot mutate ${key} via component-owned topics`
299
+ );
300
+ case "status":
301
+ applyTopicStatusPatch(plan, rawValue);
302
+ return;
303
+ case "visibility":
304
+ applyTopicVisibilityPatch(plan, rawValue);
305
+ return;
306
+ case "type":
307
+ applyTopicProjectTypePatch(plan, rawValue);
308
+ return;
309
+ default:
310
+ applyTopicMetadataPatch(plan, key, rawValue);
311
+ }
312
+ }
313
+ function applyTopicStatusPatch(plan, rawValue) {
314
+ const status = coerceStatus(rawValue);
315
+ if (status) {
316
+ plan.patch.status = status;
317
+ plan.topicUpdateArgs.status = status;
318
+ }
319
+ }
320
+ function applyTopicVisibilityPatch(plan, rawValue) {
321
+ const visibility = coerceVisibility(rawValue);
322
+ if (visibility) {
323
+ plan.patch.visibility = visibility;
324
+ plan.topicUpdateArgs.visibility = visibility;
325
+ }
326
+ }
327
+ function applyTopicProjectTypePatch(plan, rawValue) {
328
+ const projectType = readNonEmptyString(rawValue);
329
+ if (projectType) {
330
+ plan.nextMetadata.projectType = projectType;
331
+ return;
293
332
  }
294
- patch.updatedAt = Date.now();
295
- patch.metadata = nextMetadata;
296
- topicUpdateArgs.metadata = nextMetadata;
333
+ plan.nextMetadata = omitMetadataKey(plan.nextMetadata, "projectType");
334
+ }
335
+ function applyTopicMetadataPatch(plan, key, rawValue) {
336
+ if (rawValue === void 0) {
337
+ plan.nextMetadata = omitMetadataKey(plan.nextMetadata, key);
338
+ return;
339
+ }
340
+ plan.nextMetadata[key] = rawValue;
341
+ }
342
+ async function applyTopicProjectOverlayPatch(ctx, topic, plan) {
297
343
  if (typeof ctx.runMutation === "function") {
298
344
  try {
299
- await ctx.runMutation(api.topics.update, topicUpdateArgs);
345
+ await ctx.runMutation(api.topics.update, plan.topicUpdateArgs);
300
346
  } catch (error) {
301
- if (!isMissingLucernChildComponentError(error) || !ctx?.db || typeof ctx.db.patch !== "function") {
347
+ if (!canPatchTopicViaLocalDb(ctx, error)) {
302
348
  throw error;
303
349
  }
304
- await ctx.db.patch(String(topic._id), patch);
350
+ await ctx.db.patch(topic._id, plan.patch);
305
351
  }
306
352
  } else if (ctx?.db && typeof ctx.db.patch === "function") {
307
- await ctx.db.patch(String(topic._id), patch);
353
+ await ctx.db.patch(topic._id, plan.patch);
308
354
  } else {
309
355
  throw new Error(
310
356
  "Cannot patch topic without component adapter (ctx.runMutation unavailable)"
311
357
  );
312
358
  }
313
- return materializeTopicProjectOverlay({
314
- ...topic,
315
- ...patch,
316
- metadata: nextMetadata
317
- });
359
+ }
360
+ function canPatchTopicViaLocalDb(ctx, error) {
361
+ return isMissingLucernChildComponentError(error) && Boolean(ctx?.db) && typeof ctx.db?.patch === "function";
318
362
  }
319
363
 
320
364
  // src/resolvers.ts
@@ -342,7 +386,7 @@ async function patchProjectWithTolerance(ctx, projectId, value) {
342
386
  try {
343
387
  await patchTopicProjectOverlay(ctx, projectId, value);
344
388
  } catch (error) {
345
- if (!isAdvisoryTopicPatch(value) || !isMissingLucernChildComponentError2(error)) {
389
+ if (!(isAdvisoryTopicPatch(value) && isMissingLucernChildComponentError2(error))) {
346
390
  throw error;
347
391
  }
348
392
  console.warn(
@@ -409,13 +453,15 @@ function asMappedProjectId(topic) {
409
453
  if (!topic) {
410
454
  return;
411
455
  }
412
- const directLegacyProjectId = normalizeScopeValue(topic[LEGACY_SCOPE_FIELD2]);
456
+ const directLegacyProjectId = normalizeScopeValue(
457
+ topic[LEGACY_SCOPE_FIELD2]
458
+ );
413
459
  if (directLegacyProjectId) {
414
460
  return directLegacyProjectId;
415
461
  }
416
462
  const metadata = topic.metadata || {};
417
463
  const candidate = metadata[LEGACY_SCOPE_FIELD2] || metadata.legacyProjectId || metadata.projectId || metadata.scopeProjectId;
418
- return candidate ? candidate : void 0;
464
+ return typeof candidate === "string" ? normalizeScopeValue(candidate) : void 0;
419
465
  }
420
466
  function normalizeScopeValue(value) {
421
467
  if (typeof value !== "string") {
@@ -440,8 +486,9 @@ function pickPrimaryTopic(candidates) {
440
486
  })[0];
441
487
  }
442
488
  async function findTopicsByScopeAlias(ctx, scopeId) {
489
+ const query2 = ctx.db.query("topics");
443
490
  try {
444
- return await ctx.db.query("topics").withIndex(
491
+ return await query2.withIndex(
445
492
  "by_graph_scope_project",
446
493
  (q) => q.eq(LEGACY_SCOPE_FIELD2, scopeId)
447
494
  ).collect();
@@ -453,7 +500,7 @@ async function findTopicsByScopeAlias(ctx, scopeId) {
453
500
  scopeId
454
501
  }
455
502
  );
456
- const topics = await ctx.db.query("topics").collect();
503
+ const topics = await query2.collect();
457
504
  return topics.filter((topic) => {
458
505
  const normalizedGlobalId = normalizeScopeValue(topic.globalId);
459
506
  const mappedProjectId = asMappedProjectId(topic);
@@ -509,137 +556,115 @@ async function resolveInheritedWorkspaceScope(ctx, topic) {
509
556
  let current = topic;
510
557
  for (let i = 0; i < MAX_DEPTH && current?.parentTopicId; i++) {
511
558
  current = await ctx.db.get(current.parentTopicId);
512
- if (!current) break;
559
+ if (!current) {
560
+ break;
561
+ }
513
562
  if (!tenantId) {
514
563
  tenantId = normalizeScopeValue(current.tenantId);
515
564
  }
516
565
  if (!workspaceId) {
517
566
  workspaceId = normalizeScopeValue(current.workspaceId);
518
567
  }
519
- if (tenantId && workspaceId) break;
568
+ if (tenantId && workspaceId) {
569
+ break;
570
+ }
520
571
  }
521
572
  return { tenantId, workspaceId };
522
573
  }
523
574
  async function resolveTopicProjectScope(ctx, args) {
524
575
  if (args.topicId) {
525
- let topic = null;
526
- try {
527
- topic = await ctx.db.get(
528
- args.topicId
529
- );
530
- } catch (error) {
531
- debugGraphPrimitiveFallback(
532
- "[topicScope] Failed to load topic by direct id",
533
- {
534
- error,
535
- topicId: args.topicId
536
- }
537
- );
538
- }
539
- if (!topic) {
540
- topic = await tryResolveHostTopicById(ctx, String(args.topicId));
541
- }
542
- if (!topic) {
543
- topic = pickPrimaryTopic(
544
- await findTopicsByScopeAlias(ctx, String(args.topicId))
545
- ) ?? null;
546
- }
547
- if (!topic) {
548
- const nodeScope = await resolveTopicNodeScopeOrNull(
549
- ctx,
550
- String(args.topicId)
551
- );
552
- if (nodeScope) {
553
- return nodeScope;
554
- }
555
- throw new Error(`Topic not found: ${String(args.topicId)}`);
556
- }
557
- const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
558
- const mapped = asMappedProjectId(topic);
559
- if (mapped) {
560
- return {
561
- topicId: topic._id,
562
- projectId: mapped,
563
- tenantId: inherited.tenantId,
564
- workspaceId: inherited.workspaceId,
565
- source: "topic"
566
- };
567
- }
568
- return {
569
- topicId: topic._id,
570
- tenantId: inherited.tenantId,
571
- workspaceId: inherited.workspaceId,
572
- source: "topic"
573
- };
576
+ return await resolveScopeFromTopicId(ctx, args.topicId);
574
577
  }
575
578
  if (args.projectId) {
576
- let directTopic = null;
577
- try {
578
- directTopic = await ctx.db.get(
579
- args.projectId
580
- );
581
- } catch (error) {
582
- debugGraphPrimitiveFallback(
583
- "[topicScope] Failed to load direct project topic",
584
- {
585
- error,
586
- projectId: args.projectId
587
- }
588
- );
589
- }
590
- if (directTopic) {
591
- const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
592
- const mapped = asMappedProjectId(directTopic);
593
- return {
594
- topicId: directTopic._id,
595
- projectId: mapped ?? args.projectId,
596
- tenantId: inherited.tenantId,
597
- workspaceId: inherited.workspaceId,
598
- source: "topic_inferred"
599
- };
600
- }
601
- directTopic = await tryResolveHostTopicByLegacyScope(ctx, args.projectId);
602
- if (directTopic) {
603
- const inherited = await resolveInheritedWorkspaceScope(ctx, directTopic);
604
- const mapped = asMappedProjectId(directTopic);
605
- return {
606
- topicId: directTopic._id,
607
- projectId: mapped ?? args.projectId,
608
- tenantId: inherited.tenantId,
609
- workspaceId: inherited.workspaceId,
610
- source: "topic_inferred"
611
- };
612
- }
613
- const topics = await findTopicsByScopeAlias(ctx, args.projectId);
614
- const primary = pickPrimaryTopic(topics);
615
- if (primary) {
616
- const inherited = await resolveInheritedWorkspaceScope(ctx, primary);
617
- return {
618
- topicId: primary._id,
619
- projectId: args.projectId,
620
- tenantId: inherited.tenantId,
621
- workspaceId: inherited.workspaceId,
622
- source: "project_mapped_topic"
623
- };
624
- }
625
- const nodeScope = await resolveTopicNodeScopeOrNull(
626
- ctx,
627
- String(args.projectId)
628
- );
629
- if (nodeScope) {
630
- return {
631
- ...nodeScope,
632
- projectId: nodeScope.projectId ?? String(args.projectId)
633
- };
634
- }
635
- throw new Error(
636
- `Legacy project scope ${String(args.projectId)} has no mapped topic.`
637
- );
579
+ return await resolveScopeFromLegacyProjectId(ctx, args.projectId);
638
580
  }
639
581
  throw new Error(
640
582
  "Missing scope: provide topicId (preferred) or legacy projectId alias."
641
583
  );
642
584
  }
585
+ async function resolveScopeFromTopicId(ctx, topicId) {
586
+ const topic = await resolveTopicDocFromTopicId(ctx, topicId);
587
+ if (topic) {
588
+ return await buildTopicScope(ctx, topic, "topic");
589
+ }
590
+ const nodeScope = await resolveTopicNodeScopeOrNull(ctx, String(topicId));
591
+ if (nodeScope) {
592
+ return nodeScope;
593
+ }
594
+ throw new Error(`Topic not found: ${String(topicId)}`);
595
+ }
596
+ async function resolveTopicDocFromTopicId(ctx, topicId) {
597
+ const direct = await tryReadTopicDoc(ctx, topicId, {
598
+ failureLog: "[topicScope] Failed to load topic by direct id",
599
+ idLogKey: "topicId"
600
+ });
601
+ if (direct) {
602
+ return direct;
603
+ }
604
+ const hostTopic = await tryResolveHostTopicById(ctx, String(topicId));
605
+ if (hostTopic) {
606
+ return hostTopic;
607
+ }
608
+ return pickPrimaryTopic(await findTopicsByScopeAlias(ctx, String(topicId))) ?? null;
609
+ }
610
+ async function resolveScopeFromLegacyProjectId(ctx, legacyProjectId) {
611
+ const directTopic = await resolveDirectLegacyProjectTopic(
612
+ ctx,
613
+ legacyProjectId
614
+ );
615
+ if (directTopic) {
616
+ return await buildTopicScope(ctx, directTopic, "topic_inferred", {
617
+ fallbackProjectId: legacyProjectId
618
+ });
619
+ }
620
+ const primary = pickPrimaryTopic(
621
+ await findTopicsByScopeAlias(ctx, legacyProjectId)
622
+ );
623
+ if (primary) {
624
+ return await buildTopicScope(ctx, primary, "project_mapped_topic", {
625
+ fallbackProjectId: legacyProjectId
626
+ });
627
+ }
628
+ const nodeScope = await resolveTopicNodeScopeOrNull(ctx, legacyProjectId);
629
+ if (nodeScope) {
630
+ return {
631
+ ...nodeScope,
632
+ projectId: nodeScope.projectId ?? legacyProjectId
633
+ };
634
+ }
635
+ throw new Error(
636
+ `Legacy project scope ${legacyProjectId} has no mapped topic.`
637
+ );
638
+ }
639
+ async function resolveDirectLegacyProjectTopic(ctx, legacyProjectId) {
640
+ const directTopic = await tryReadTopicDoc(ctx, legacyProjectId, {
641
+ failureLog: "[topicScope] Failed to load direct project topic",
642
+ idLogKey: "projectId"
643
+ });
644
+ return directTopic ?? tryResolveHostTopicByLegacyScope(ctx, legacyProjectId);
645
+ }
646
+ async function tryReadTopicDoc(ctx, id, log) {
647
+ try {
648
+ return await ctx.db.get(id);
649
+ } catch (error) {
650
+ debugGraphPrimitiveFallback(log.failureLog, {
651
+ error,
652
+ [log.idLogKey]: id
653
+ });
654
+ return null;
655
+ }
656
+ }
657
+ async function buildTopicScope(ctx, topic, source, options = {}) {
658
+ const inherited = await resolveInheritedWorkspaceScope(ctx, topic);
659
+ const mapped = asMappedProjectId(topic);
660
+ return {
661
+ topicId: topic._id,
662
+ ...mapped || options.fallbackProjectId ? { projectId: mapped ?? options.fallbackProjectId } : {},
663
+ tenantId: inherited.tenantId,
664
+ workspaceId: inherited.workspaceId,
665
+ source
666
+ };
667
+ }
643
668
  ({
644
669
  projectId: v.optional(v.string()),
645
670
  topicId: v.optional(v.string())
@@ -653,9 +678,14 @@ var defineEpistemicInternalQuery = internalQuery;
653
678
  function generateContentHash(text) {
654
679
  const content = `question:${text.trim().toLowerCase().replace(/\s+/g, " ")}`;
655
680
  let hash = 5381;
681
+ const maxSigned32Bit = 2147483647;
682
+ const uint32Size = 4294967296;
656
683
  for (let i = 0; i < content.length; i++) {
657
- hash = (hash << 5) + hash + content.charCodeAt(i);
658
- hash &= hash;
684
+ hash = Math.imul(hash, 33) + content.charCodeAt(i);
685
+ hash %= uint32Size;
686
+ if (hash > maxSigned32Bit) {
687
+ hash -= uint32Size;
688
+ }
659
689
  }
660
690
  return Math.abs(hash).toString(16).padStart(8, "0");
661
691
  }
@@ -663,9 +693,10 @@ function buildTestsEdgeGlobalId(fromGlobalId, toGlobalId) {
663
693
  return `edge-${fromGlobalId}-tests-${toGlobalId}`;
664
694
  }
665
695
  async function markProjectGraphDirty(ctx, projectId, topicId) {
696
+ const markCacheStaleByTopic = internal.graphAnalysisCache.markCacheStaleByTopic;
666
697
  const normalizedProjectId = typeof projectId === "string" && projectId.trim().length > 0 ? projectId : void 0;
667
698
  const normalizedTopicId = typeof topicId === "string" && topicId.trim().length > 0 ? topicId : void 0;
668
- if (!normalizedProjectId && !normalizedTopicId) {
699
+ if (!(normalizedProjectId || normalizedTopicId)) {
669
700
  return;
670
701
  }
671
702
  if (normalizedProjectId) {
@@ -678,17 +709,17 @@ async function markProjectGraphDirty(ctx, projectId, topicId) {
678
709
  );
679
710
  }
680
711
  if (normalizedTopicId) {
681
- await ctx.scheduler.runAfter(
682
- 0,
683
- internal.graphAnalysisCache.markCacheStaleByTopic,
684
- {
685
- topicId: normalizedTopicId
686
- }
687
- );
712
+ await ctx.scheduler.runAfter(0, markCacheStaleByTopic, {
713
+ topicId: normalizedTopicId
714
+ });
715
+ }
716
+ const resolvedProjectId = normalizedTopicId ?? normalizedProjectId;
717
+ if (!resolvedProjectId) {
718
+ return;
688
719
  }
689
720
  await resolveGraphPrimitivesAppResolvers().patchProject(
690
721
  ctx,
691
- normalizedTopicId ?? normalizedProjectId,
722
+ resolvedProjectId,
692
723
  {
693
724
  lastActivityAt: Date.now()
694
725
  }
@@ -750,7 +781,7 @@ function logQuestionFallback(message, error, context) {
750
781
  });
751
782
  }
752
783
  async function resolveQuestionScopeOrNull(ctx, args) {
753
- if (!args.projectId && !args.topicId) {
784
+ if (!(args.projectId || args.topicId)) {
754
785
  return null;
755
786
  }
756
787
  try {
@@ -824,7 +855,7 @@ function flattenQuestionNode(n) {
824
855
  linkedBeliefId: meta.linkedBeliefNodeId || null,
825
856
  testType: meta.testType || "validates",
826
857
  importance: meta.importance || 5,
827
- isKeyQuestion: meta.isKeyQuestion || false,
858
+ isKeyQuestion: Boolean(meta.isKeyQuestion),
828
859
  answer: meta.answer || null,
829
860
  convictionStage: meta.convictionStage || null,
830
861
  conviction: meta.conviction ?? null,
@@ -859,7 +890,7 @@ function getQuestionStatusCandidates(node) {
859
890
  );
860
891
  }
861
892
  function isActiveQuestionNode(node) {
862
- if (INACTIVE_NODE_STATUSES.has(node.status)) {
893
+ if (typeof node.status === "string" && INACTIVE_NODE_STATUSES.has(node.status)) {
863
894
  return false;
864
895
  }
865
896
  return !getQuestionStatusCandidates(node).some(