@harperfast/harper 5.2.10 → 5.3.0-alpha.1

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 (554) hide show
  1. package/agent/mcpTools.ts +1 -1
  2. package/agent/session.ts +25 -14
  3. package/bin/cliOperations.ts +46 -9
  4. package/bin/copyDb.ts +282 -59
  5. package/bin/deploySetup.ts +16 -5
  6. package/bin/harper.ts +1 -1
  7. package/bin/help.ts +4 -1
  8. package/bin/lite.ts +4 -1
  9. package/bin/restart.ts +59 -3
  10. package/bin/run.ts +6 -11
  11. package/bin/upgrade.js +7 -3
  12. package/bin/workloadIdentity.ts +119 -0
  13. package/components/Application.ts +2414 -242
  14. package/components/ApplicationScope.ts +8 -0
  15. package/components/EntryHandler.ts +59 -39
  16. package/components/OptionsWatcher.ts +150 -74
  17. package/components/RuntimeModuleTracker.ts +38 -7
  18. package/components/Scope.ts +37 -15
  19. package/components/awaitRestart.ts +84 -0
  20. package/components/componentLoader.ts +340 -30
  21. package/components/componentPreparationLock.ts +16 -5
  22. package/components/mcp/adapters/harperHttp.ts +4 -0
  23. package/components/mcp/listChanged.ts +4 -0
  24. package/components/mcp/toolRegistry.ts +2 -0
  25. package/components/mcp/tools/operations.ts +9 -0
  26. package/components/mcp/tools/schemas/operationDescriptions.ts +2 -2
  27. package/components/operations.js +270 -78
  28. package/components/operationsValidation.js +49 -1
  29. package/components/status/ComponentStatusRegistry.ts +59 -0
  30. package/config/RootConfigWatcher.ts +80 -34
  31. package/config/configUtils.ts +291 -34
  32. package/config/harperConfigEnvVars.ts +170 -27
  33. package/config-root.schema.json +29 -0
  34. package/dataLayer/blobBackup.ts +160 -50
  35. package/dataLayer/delete.ts +6 -1
  36. package/dataLayer/harperBridge/ResourceBridge.ts +52 -8
  37. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
  38. package/dataLayer/hdbInfoController.ts +34 -1
  39. package/dataLayer/insert.ts +44 -1
  40. package/dataLayer/rocksdbBackup.ts +53 -10
  41. package/dataLayer/schema.ts +11 -1
  42. package/dataLayer/schemaDescribe.ts +8 -1
  43. package/dist/agent/mcpTools.js +1 -1
  44. package/dist/agent/mcpTools.js.map +1 -1
  45. package/dist/agent/session.d.ts +22 -0
  46. package/dist/agent/session.js +26 -15
  47. package/dist/agent/session.js.map +1 -1
  48. package/dist/bin/cliOperations.js +48 -9
  49. package/dist/bin/cliOperations.js.map +1 -1
  50. package/dist/bin/copyDb.d.ts +12 -1
  51. package/dist/bin/copyDb.js +248 -60
  52. package/dist/bin/copyDb.js.map +1 -1
  53. package/dist/bin/deploySetup.d.ts +2 -0
  54. package/dist/bin/deploySetup.js +11 -3
  55. package/dist/bin/deploySetup.js.map +1 -1
  56. package/dist/bin/harper.js +1 -1
  57. package/dist/bin/harper.js.map +1 -1
  58. package/dist/bin/help.js +4 -1
  59. package/dist/bin/help.js.map +1 -1
  60. package/dist/bin/lite.js +4 -1
  61. package/dist/bin/lite.js.map +1 -1
  62. package/dist/bin/restart.js +54 -5
  63. package/dist/bin/restart.js.map +1 -1
  64. package/dist/bin/run.js +4 -10
  65. package/dist/bin/run.js.map +1 -1
  66. package/dist/bin/upgrade.js +4 -3
  67. package/dist/bin/upgrade.js.map +1 -1
  68. package/dist/bin/workloadIdentity.d.ts +18 -0
  69. package/dist/bin/workloadIdentity.js +100 -0
  70. package/dist/bin/workloadIdentity.js.map +1 -0
  71. package/dist/components/Application.d.ts +139 -16
  72. package/dist/components/Application.js +2215 -267
  73. package/dist/components/Application.js.map +1 -1
  74. package/dist/components/ApplicationScope.d.ts +8 -0
  75. package/dist/components/ApplicationScope.js +7 -0
  76. package/dist/components/ApplicationScope.js.map +1 -1
  77. package/dist/components/EntryHandler.js +26 -10
  78. package/dist/components/EntryHandler.js.map +1 -1
  79. package/dist/components/OptionsWatcher.d.ts +1 -0
  80. package/dist/components/OptionsWatcher.js +141 -74
  81. package/dist/components/OptionsWatcher.js.map +1 -1
  82. package/dist/components/RuntimeModuleTracker.js +40 -6
  83. package/dist/components/RuntimeModuleTracker.js.map +1 -1
  84. package/dist/components/Scope.js +38 -13
  85. package/dist/components/Scope.js.map +1 -1
  86. package/dist/components/awaitRestart.d.ts +33 -0
  87. package/dist/components/awaitRestart.js +61 -0
  88. package/dist/components/awaitRestart.js.map +1 -0
  89. package/dist/components/componentLoader.d.ts +38 -1
  90. package/dist/components/componentLoader.js +279 -22
  91. package/dist/components/componentLoader.js.map +1 -1
  92. package/dist/components/componentPreparationLock.d.ts +5 -0
  93. package/dist/components/componentPreparationLock.js +14 -6
  94. package/dist/components/componentPreparationLock.js.map +1 -1
  95. package/dist/components/mcp/adapters/harperHttp.js +4 -0
  96. package/dist/components/mcp/adapters/harperHttp.js.map +1 -1
  97. package/dist/components/mcp/listChanged.js +5 -0
  98. package/dist/components/mcp/listChanged.js.map +1 -1
  99. package/dist/components/mcp/toolRegistry.d.ts +1 -0
  100. package/dist/components/mcp/toolRegistry.js.map +1 -1
  101. package/dist/components/mcp/tools/operations.d.ts +5 -0
  102. package/dist/components/mcp/tools/operations.js +9 -0
  103. package/dist/components/mcp/tools/operations.js.map +1 -1
  104. package/dist/components/mcp/tools/schemas/operationDescriptions.js +2 -2
  105. package/dist/components/mcp/tools/schemas/operationDescriptions.js.map +1 -1
  106. package/dist/components/operations.js +231 -77
  107. package/dist/components/operations.js.map +1 -1
  108. package/dist/components/operationsValidation.js +49 -1
  109. package/dist/components/operationsValidation.js.map +1 -1
  110. package/dist/components/status/ComponentStatusRegistry.d.ts +0 -4
  111. package/dist/components/status/ComponentStatusRegistry.js +63 -0
  112. package/dist/components/status/ComponentStatusRegistry.js.map +1 -1
  113. package/dist/config/RootConfigWatcher.d.ts +7 -1
  114. package/dist/config/RootConfigWatcher.js +64 -27
  115. package/dist/config/RootConfigWatcher.js.map +1 -1
  116. package/dist/config/configUtils.d.ts +9 -1
  117. package/dist/config/configUtils.js +254 -33
  118. package/dist/config/configUtils.js.map +1 -1
  119. package/dist/config/harperConfigEnvVars.d.ts +16 -0
  120. package/dist/config/harperConfigEnvVars.js +162 -25
  121. package/dist/config/harperConfigEnvVars.js.map +1 -1
  122. package/dist/dataLayer/blobBackup.d.ts +49 -20
  123. package/dist/dataLayer/blobBackup.js +139 -50
  124. package/dist/dataLayer/blobBackup.js.map +1 -1
  125. package/dist/dataLayer/delete.js +1 -1
  126. package/dist/dataLayer/delete.js.map +1 -1
  127. package/dist/dataLayer/harperBridge/ResourceBridge.d.ts +14 -1
  128. package/dist/dataLayer/harperBridge/ResourceBridge.js +51 -10
  129. package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
  130. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.d.ts +3 -1
  131. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js +3 -1
  132. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/DeleteAuditLogsBeforeResults.js.map +1 -1
  133. package/dist/dataLayer/hdbInfoController.d.ts +10 -0
  134. package/dist/dataLayer/hdbInfoController.js +30 -1
  135. package/dist/dataLayer/hdbInfoController.js.map +1 -1
  136. package/dist/dataLayer/insert.d.ts +9 -1
  137. package/dist/dataLayer/insert.js +30 -0
  138. package/dist/dataLayer/insert.js.map +1 -1
  139. package/dist/dataLayer/rocksdbBackup.d.ts +2 -2
  140. package/dist/dataLayer/rocksdbBackup.js +45 -8
  141. package/dist/dataLayer/rocksdbBackup.js.map +1 -1
  142. package/dist/dataLayer/schema.js +8 -0
  143. package/dist/dataLayer/schema.js.map +1 -1
  144. package/dist/dataLayer/schemaDescribe.js +8 -1
  145. package/dist/dataLayer/schemaDescribe.js.map +1 -1
  146. package/dist/index.d.ts +1 -1
  147. package/dist/index.js.map +1 -1
  148. package/dist/json/systemSchema.json +52 -0
  149. package/dist/resources/DatabaseTransaction.d.ts +55 -3
  150. package/dist/resources/DatabaseTransaction.js +460 -134
  151. package/dist/resources/DatabaseTransaction.js.map +1 -1
  152. package/dist/resources/LMDBTransaction.js +22 -4
  153. package/dist/resources/LMDBTransaction.js.map +1 -1
  154. package/dist/resources/PrimaryRocksDatabase.d.ts +1 -0
  155. package/dist/resources/PrimaryRocksDatabase.js +30 -2
  156. package/dist/resources/PrimaryRocksDatabase.js.map +1 -1
  157. package/dist/resources/RecordEncoder.d.ts +20 -0
  158. package/dist/resources/RecordEncoder.js +94 -9
  159. package/dist/resources/RecordEncoder.js.map +1 -1
  160. package/dist/resources/RequestTarget.d.ts +2 -0
  161. package/dist/resources/RequestTarget.js.map +1 -1
  162. package/dist/resources/Resource.js +20 -11
  163. package/dist/resources/Resource.js.map +1 -1
  164. package/dist/resources/ResourceInterface.d.ts +20 -1
  165. package/dist/resources/ResourceInterface.js.map +1 -1
  166. package/dist/resources/RocksIndexStore.d.ts +6 -1
  167. package/dist/resources/RocksIndexStore.js +24 -10
  168. package/dist/resources/RocksIndexStore.js.map +1 -1
  169. package/dist/resources/RocksTransactionLogStore.d.ts +14 -1
  170. package/dist/resources/RocksTransactionLogStore.js +57 -17
  171. package/dist/resources/RocksTransactionLogStore.js.map +1 -1
  172. package/dist/resources/Table.d.ts +112 -8
  173. package/dist/resources/Table.js +1071 -197
  174. package/dist/resources/Table.js.map +1 -1
  175. package/dist/resources/auditStore.d.ts +11 -2
  176. package/dist/resources/auditStore.js +183 -18
  177. package/dist/resources/auditStore.js.map +1 -1
  178. package/dist/resources/blob.d.ts +129 -9
  179. package/dist/resources/blob.js +992 -114
  180. package/dist/resources/blob.js.map +1 -1
  181. package/dist/resources/branchDatabase.d.ts +48 -0
  182. package/dist/resources/branchDatabase.js +892 -0
  183. package/dist/resources/branchDatabase.js.map +1 -0
  184. package/dist/resources/crdt.js +50 -12
  185. package/dist/resources/crdt.js.map +1 -1
  186. package/dist/resources/databases.d.ts +150 -9
  187. package/dist/resources/databases.js +1247 -525
  188. package/dist/resources/databases.js.map +1 -1
  189. package/dist/resources/defineTable.d.ts +10 -2
  190. package/dist/resources/defineTable.js +9 -1
  191. package/dist/resources/defineTable.js.map +1 -1
  192. package/dist/resources/graphql.d.ts +1 -1
  193. package/dist/resources/graphql.js +50 -15
  194. package/dist/resources/graphql.js.map +1 -1
  195. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +1 -0
  196. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +6 -2
  197. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
  198. package/dist/resources/longLivedTransactions.d.ts +71 -0
  199. package/dist/resources/longLivedTransactions.js +358 -0
  200. package/dist/resources/longLivedTransactions.js.map +1 -0
  201. package/dist/resources/models/backendRegistry.d.ts +26 -0
  202. package/dist/resources/models/backendRegistry.js +60 -2
  203. package/dist/resources/models/backendRegistry.js.map +1 -1
  204. package/dist/resources/models/bootstrap.d.ts +33 -1
  205. package/dist/resources/models/bootstrap.js +416 -31
  206. package/dist/resources/models/bootstrap.js.map +1 -1
  207. package/dist/resources/recordLock.d.ts +80 -0
  208. package/dist/resources/recordLock.js +184 -0
  209. package/dist/resources/recordLock.js.map +1 -0
  210. package/dist/resources/replayLogs.d.ts +14 -1
  211. package/dist/resources/replayLogs.js +152 -24
  212. package/dist/resources/replayLogs.js.map +1 -1
  213. package/dist/resources/replayLogsGuards.d.ts +94 -7
  214. package/dist/resources/replayLogsGuards.js +111 -7
  215. package/dist/resources/replayLogsGuards.js.map +1 -1
  216. package/dist/resources/search.js +158 -32
  217. package/dist/resources/search.js.map +1 -1
  218. package/dist/resources/transactionBroadcast.d.ts +1 -1
  219. package/dist/resources/transactionBroadcast.js +2 -2
  220. package/dist/resources/transactionBroadcast.js.map +1 -1
  221. package/dist/security/auth.js +61 -30
  222. package/dist/security/auth.js.map +1 -1
  223. package/dist/security/authn/oidc/claims.d.ts +22 -0
  224. package/dist/security/authn/oidc/claims.js +71 -0
  225. package/dist/security/authn/oidc/claims.js.map +1 -0
  226. package/dist/security/authn/oidc/identityToken.d.ts +27 -0
  227. package/dist/security/authn/oidc/identityToken.js +111 -0
  228. package/dist/security/authn/oidc/identityToken.js.map +1 -0
  229. package/dist/security/authn/oidc/jwks.d.ts +25 -0
  230. package/dist/security/authn/oidc/jwks.js +261 -0
  231. package/dist/security/authn/oidc/jwks.js.map +1 -0
  232. package/dist/security/authn/oidc/providers/generic.d.ts +13 -0
  233. package/dist/security/authn/oidc/providers/generic.js +34 -0
  234. package/dist/security/authn/oidc/providers/generic.js.map +1 -0
  235. package/dist/security/authn/oidc/providers/githubActions.d.ts +11 -0
  236. package/dist/security/authn/oidc/providers/githubActions.js +129 -0
  237. package/dist/security/authn/oidc/providers/githubActions.js.map +1 -0
  238. package/dist/security/authn/oidc/providers/index.d.ts +37 -0
  239. package/dist/security/authn/oidc/providers/index.js +24 -0
  240. package/dist/security/authn/oidc/providers/index.js.map +1 -0
  241. package/dist/security/authn/oidc/tokenExchange.d.ts +12 -0
  242. package/dist/security/authn/oidc/tokenExchange.js +306 -0
  243. package/dist/security/authn/oidc/tokenExchange.js.map +1 -0
  244. package/dist/security/authn/oidc/trustPolicyOperations.d.ts +49 -0
  245. package/dist/security/authn/oidc/trustPolicyOperations.js +358 -0
  246. package/dist/security/authn/oidc/trustPolicyOperations.js.map +1 -0
  247. package/dist/security/authn/oidc/types.d.ts +38 -0
  248. package/dist/security/authn/oidc/types.js +6 -0
  249. package/dist/security/authn/oidc/types.js.map +1 -0
  250. package/dist/security/certificateVerification/index.js +40 -11
  251. package/dist/security/certificateVerification/index.js.map +1 -1
  252. package/dist/security/certificateVerification/trustedIssuers.d.ts +24 -0
  253. package/dist/security/certificateVerification/trustedIssuers.js +79 -0
  254. package/dist/security/certificateVerification/trustedIssuers.js.map +1 -0
  255. package/dist/security/certificateVerification/types.d.ts +1 -0
  256. package/dist/security/credentialProvenance.d.ts +35 -0
  257. package/dist/security/credentialProvenance.js +51 -0
  258. package/dist/security/credentialProvenance.js.map +1 -0
  259. package/dist/security/credentialRejection.d.ts +4 -0
  260. package/dist/security/credentialRejection.js +24 -0
  261. package/dist/security/credentialRejection.js.map +1 -0
  262. package/dist/security/deferredAuthentication.d.ts +36 -0
  263. package/dist/security/deferredAuthentication.js +70 -0
  264. package/dist/security/deferredAuthentication.js.map +1 -0
  265. package/dist/security/impersonation.d.ts +21 -0
  266. package/dist/security/impersonation.js +108 -9
  267. package/dist/security/impersonation.js.map +1 -1
  268. package/dist/security/jsLoader.d.ts +6 -0
  269. package/dist/security/jsLoader.js +75 -15
  270. package/dist/security/jsLoader.js.map +1 -1
  271. package/dist/security/keys.js +301 -71
  272. package/dist/security/keys.js.map +1 -1
  273. package/dist/security/operationScope.d.ts +21 -0
  274. package/dist/security/operationScope.js +36 -0
  275. package/dist/security/operationScope.js.map +1 -0
  276. package/dist/security/permissionsTranslator.js +21 -0
  277. package/dist/security/permissionsTranslator.js.map +1 -1
  278. package/dist/security/tokenAuthentication.d.ts +19 -1
  279. package/dist/security/tokenAuthentication.js +191 -10
  280. package/dist/security/tokenAuthentication.js.map +1 -1
  281. package/dist/security/user.js +4 -3
  282. package/dist/security/user.js.map +1 -1
  283. package/dist/server/DurableSubscriptionsSession.d.ts +2 -2
  284. package/dist/server/DurableSubscriptionsSession.js +67 -10
  285. package/dist/server/DurableSubscriptionsSession.js.map +1 -1
  286. package/dist/server/REST.js +73 -0
  287. package/dist/server/REST.js.map +1 -1
  288. package/dist/server/graphqlQuerying.js +4 -0
  289. package/dist/server/graphqlQuerying.js.map +1 -1
  290. package/dist/server/http.d.ts +11 -0
  291. package/dist/server/http.js +88 -15
  292. package/dist/server/http.js.map +1 -1
  293. package/dist/server/itc/serverHandlers.js +8 -1
  294. package/dist/server/itc/serverHandlers.js.map +1 -1
  295. package/dist/server/jobs/jobProcess.js +6 -2
  296. package/dist/server/jobs/jobProcess.js.map +1 -1
  297. package/dist/server/jobs/jobs.js +4 -1
  298. package/dist/server/jobs/jobs.js.map +1 -1
  299. package/dist/server/liveSubscriptionAuth.d.ts +26 -4
  300. package/dist/server/liveSubscriptionAuth.js +105 -39
  301. package/dist/server/liveSubscriptionAuth.js.map +1 -1
  302. package/dist/server/loadRootComponents.js +49 -10
  303. package/dist/server/loadRootComponents.js.map +1 -1
  304. package/dist/server/mqtt.d.ts +2 -0
  305. package/dist/server/mqtt.js +165 -30
  306. package/dist/server/mqtt.js.map +1 -1
  307. package/dist/server/nodeName.d.ts +2 -0
  308. package/dist/server/nodeName.js +107 -23
  309. package/dist/server/nodeName.js.map +1 -1
  310. package/dist/server/serverHelpers/Headers.d.ts +25 -0
  311. package/dist/server/serverHelpers/Headers.js +139 -1
  312. package/dist/server/serverHelpers/Headers.js.map +1 -1
  313. package/dist/server/serverHelpers/contentTypes.d.ts +9 -0
  314. package/dist/server/serverHelpers/contentTypes.js +32 -25
  315. package/dist/server/serverHelpers/contentTypes.js.map +1 -1
  316. package/dist/server/serverHelpers/deployValidationState.d.ts +3 -0
  317. package/dist/server/serverHelpers/deployValidationState.js +9 -19
  318. package/dist/server/serverHelpers/deployValidationState.js.map +1 -1
  319. package/dist/server/serverHelpers/operationAuthorizationState.d.ts +12 -0
  320. package/dist/server/serverHelpers/operationAuthorizationState.js +24 -2
  321. package/dist/server/serverHelpers/operationAuthorizationState.js.map +1 -1
  322. package/dist/server/serverHelpers/registeredOperations.d.ts +5 -4
  323. package/dist/server/serverHelpers/registeredOperations.js +74 -21
  324. package/dist/server/serverHelpers/registeredOperations.js.map +1 -1
  325. package/dist/server/serverHelpers/requestSanitization.d.ts +11 -0
  326. package/dist/server/serverHelpers/requestSanitization.js +20 -0
  327. package/dist/server/serverHelpers/requestSanitization.js.map +1 -0
  328. package/dist/server/serverHelpers/serverHandlers.js +6 -3
  329. package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
  330. package/dist/server/serverHelpers/serverUtilities.d.ts +18 -0
  331. package/dist/server/serverHelpers/serverUtilities.js +90 -20
  332. package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
  333. package/dist/server/serverHelpers/sharedMessageEncoding.d.ts +67 -0
  334. package/dist/server/serverHelpers/sharedMessageEncoding.js +280 -0
  335. package/dist/server/serverHelpers/sharedMessageEncoding.js.map +1 -0
  336. package/dist/server/serverHelpers/uwsServer.js +19 -1
  337. package/dist/server/serverHelpers/uwsServer.js.map +1 -1
  338. package/dist/server/static.js +24 -28
  339. package/dist/server/static.js.map +1 -1
  340. package/dist/server/storageReclamation.d.ts +5 -0
  341. package/dist/server/storageReclamation.js +16 -0
  342. package/dist/server/storageReclamation.js.map +1 -1
  343. package/dist/server/threads/itc.d.ts +7 -2
  344. package/dist/server/threads/itc.js +5 -1
  345. package/dist/server/threads/itc.js.map +1 -1
  346. package/dist/server/threads/manageThreads.d.ts +26 -4
  347. package/dist/server/threads/manageThreads.js +517 -72
  348. package/dist/server/threads/manageThreads.js.map +1 -1
  349. package/dist/server/threads/socketRouter.js +89 -26
  350. package/dist/server/threads/socketRouter.js.map +1 -1
  351. package/dist/server/threads/threadHeapMemory.d.ts +2 -0
  352. package/dist/server/threads/threadHeapMemory.js +31 -0
  353. package/dist/server/threads/threadHeapMemory.js.map +1 -0
  354. package/dist/server/threads/threadServer.js +46 -15
  355. package/dist/server/threads/threadServer.js.map +1 -1
  356. package/dist/sqlEngine/config.d.ts +1 -3
  357. package/dist/sqlEngine/config.js +19 -16
  358. package/dist/sqlEngine/config.js.map +1 -1
  359. package/dist/sqlTranslator/index.d.ts +1 -1
  360. package/dist/sqlTranslator/index.js +30 -7
  361. package/dist/sqlTranslator/index.js.map +1 -1
  362. package/dist/upgrade/directives/5-3-0.d.ts +7 -0
  363. package/dist/upgrade/directives/5-3-0.js +148 -0
  364. package/dist/upgrade/directives/5-3-0.js.map +1 -0
  365. package/dist/upgrade/directives/directivesController.js +2 -1
  366. package/dist/upgrade/directives/directivesController.js.map +1 -1
  367. package/dist/utility/OperationFunctionCaller.js +2 -1
  368. package/dist/utility/OperationFunctionCaller.js.map +1 -1
  369. package/dist/utility/common_utils.d.ts +16 -0
  370. package/dist/utility/common_utils.js +32 -6
  371. package/dist/utility/common_utils.js.map +1 -1
  372. package/dist/utility/componentNames.d.ts +8 -0
  373. package/dist/utility/componentNames.js +12 -1
  374. package/dist/utility/componentNames.js.map +1 -1
  375. package/dist/utility/environment/environmentManager.js +3 -6
  376. package/dist/utility/environment/environmentManager.js.map +1 -1
  377. package/dist/utility/environment/systemInformation.d.ts +1 -0
  378. package/dist/utility/environment/systemInformation.js +1 -0
  379. package/dist/utility/environment/systemInformation.js.map +1 -1
  380. package/dist/utility/errors/commonErrors.d.ts +2 -0
  381. package/dist/utility/errors/commonErrors.js +2 -0
  382. package/dist/utility/errors/commonErrors.js.map +1 -1
  383. package/dist/utility/errors/hdbError.d.ts +17 -0
  384. package/dist/utility/errors/hdbError.js +30 -1
  385. package/dist/utility/errors/hdbError.js.map +1 -1
  386. package/dist/utility/globalSchema.d.ts +18 -0
  387. package/dist/utility/hdbTerms.d.ts +16 -0
  388. package/dist/utility/hdbTerms.js +18 -2
  389. package/dist/utility/hdbTerms.js.map +1 -1
  390. package/dist/utility/logging/harper_logger.d.ts +2 -0
  391. package/dist/utility/logging/harper_logger.js +91 -14
  392. package/dist/utility/logging/harper_logger.js.map +1 -1
  393. package/dist/utility/logging/logRotator.js +76 -49
  394. package/dist/utility/logging/logRotator.js.map +1 -1
  395. package/dist/utility/nodeIdentity.d.ts +9 -0
  396. package/dist/utility/nodeIdentity.js +58 -0
  397. package/dist/utility/nodeIdentity.js.map +1 -0
  398. package/dist/utility/npmUtilities.js +9 -7
  399. package/dist/utility/npmUtilities.js.map +1 -1
  400. package/dist/utility/operationPermissions.d.ts +3 -1
  401. package/dist/utility/operationPermissions.js +16 -1
  402. package/dist/utility/operationPermissions.js.map +1 -1
  403. package/dist/utility/operation_authorization.d.ts +10 -7
  404. package/dist/utility/operation_authorization.js +212 -41
  405. package/dist/utility/operation_authorization.js.map +1 -1
  406. package/dist/utility/watchPath.d.ts +29 -0
  407. package/dist/utility/watchPath.js +68 -0
  408. package/dist/utility/watchPath.js.map +1 -0
  409. package/dist/utility/watcherFallback.d.ts +86 -0
  410. package/dist/utility/watcherFallback.js +278 -1
  411. package/dist/utility/watcherFallback.js.map +1 -1
  412. package/dist/validation/configValidator.d.ts +12 -0
  413. package/dist/validation/configValidator.js +199 -72
  414. package/dist/validation/configValidator.js.map +1 -1
  415. package/dist/validation/installValidator.js +12 -0
  416. package/dist/validation/installValidator.js.map +1 -1
  417. package/dist/validation/validationWrapper.d.ts +11 -0
  418. package/dist/validation/validationWrapper.js +16 -3
  419. package/dist/validation/validationWrapper.js.map +1 -1
  420. package/index.ts +2 -0
  421. package/json/systemSchema.json +52 -0
  422. package/npm-shrinkwrap.json +235 -233
  423. package/package.json +8 -7
  424. package/resources/DESIGN.md +114 -52
  425. package/resources/DatabaseTransaction.ts +522 -130
  426. package/resources/LMDBTransaction.ts +26 -4
  427. package/resources/PrimaryRocksDatabase.ts +29 -3
  428. package/resources/RecordEncoder.ts +103 -8
  429. package/resources/RequestTarget.ts +2 -0
  430. package/resources/Resource.ts +17 -9
  431. package/resources/ResourceInterface.ts +23 -0
  432. package/resources/RocksIndexStore.ts +30 -10
  433. package/resources/RocksTransactionLogStore.ts +78 -21
  434. package/resources/Table.ts +1107 -164
  435. package/resources/auditStore.ts +187 -21
  436. package/resources/blob.ts +1029 -110
  437. package/resources/branchDatabase.ts +941 -0
  438. package/resources/crdt.ts +76 -12
  439. package/resources/databases.ts +1354 -522
  440. package/resources/defineTable.ts +18 -2
  441. package/resources/graphql.ts +70 -16
  442. package/resources/indexes/HierarchicalNavigableSmallWorld.ts +6 -2
  443. package/resources/longLivedTransactions.ts +360 -0
  444. package/resources/models/backendRegistry.ts +84 -2
  445. package/resources/models/bootstrap.ts +473 -28
  446. package/resources/recordLock.ts +253 -0
  447. package/resources/replayLogs.ts +147 -26
  448. package/resources/replayLogsGuards.ts +171 -8
  449. package/resources/search.ts +154 -32
  450. package/resources/transactionBroadcast.ts +3 -3
  451. package/security/auth.ts +68 -29
  452. package/security/authn/oidc/claims.ts +72 -0
  453. package/security/authn/oidc/identityToken.ts +129 -0
  454. package/security/authn/oidc/jwks.ts +260 -0
  455. package/security/authn/oidc/providers/generic.ts +40 -0
  456. package/security/authn/oidc/providers/githubActions.ts +137 -0
  457. package/security/authn/oidc/providers/index.ts +52 -0
  458. package/security/authn/oidc/tokenExchange.ts +300 -0
  459. package/security/authn/oidc/trustPolicyOperations.ts +343 -0
  460. package/security/authn/oidc/types.ts +41 -0
  461. package/security/certificateVerification/index.ts +54 -13
  462. package/security/certificateVerification/trustedIssuers.ts +76 -0
  463. package/security/certificateVerification/types.ts +1 -0
  464. package/security/credentialProvenance.ts +47 -0
  465. package/security/credentialRejection.ts +22 -0
  466. package/security/deferredAuthentication.ts +71 -0
  467. package/security/impersonation.ts +117 -12
  468. package/security/jsLoader.ts +81 -18
  469. package/security/keys.ts +298 -72
  470. package/security/operationScope.ts +33 -0
  471. package/security/permissionsTranslator.js +23 -0
  472. package/security/tokenAuthentication.ts +233 -12
  473. package/security/user.ts +4 -3
  474. package/server/DESIGN.md +183 -16
  475. package/server/DurableSubscriptionsSession.ts +71 -11
  476. package/server/REST.ts +79 -1
  477. package/server/graphqlQuerying.ts +4 -0
  478. package/server/http.ts +99 -18
  479. package/server/itc/serverHandlers.js +8 -1
  480. package/server/jobs/jobProcess.ts +8 -2
  481. package/server/jobs/jobs.ts +4 -1
  482. package/server/liveSubscriptionAuth.ts +129 -46
  483. package/server/loadRootComponents.js +50 -8
  484. package/server/mqtt.ts +179 -38
  485. package/server/nodeName.ts +103 -21
  486. package/server/serverHelpers/Headers.ts +131 -0
  487. package/server/serverHelpers/contentTypes.ts +29 -21
  488. package/server/serverHelpers/deployValidationState.ts +24 -13
  489. package/server/serverHelpers/operationAuthorizationState.ts +34 -3
  490. package/server/serverHelpers/registeredOperations.ts +79 -22
  491. package/server/serverHelpers/requestSanitization.ts +15 -0
  492. package/server/serverHelpers/serverHandlers.js +6 -3
  493. package/server/serverHelpers/serverUtilities.ts +104 -31
  494. package/server/serverHelpers/sharedMessageEncoding.ts +307 -0
  495. package/server/serverHelpers/uwsServer.ts +17 -2
  496. package/server/static.ts +23 -29
  497. package/server/storageReclamation.ts +13 -0
  498. package/server/threads/itc.js +11 -1
  499. package/server/threads/manageThreads.js +526 -63
  500. package/server/threads/socketRouter.ts +81 -26
  501. package/server/threads/threadHeapMemory.ts +26 -0
  502. package/server/threads/threadServer.js +43 -15
  503. package/sqlTranslator/index.ts +31 -8
  504. package/studio/web/assets/{Chat-Br06zdMA.js → Chat-BnCBegQz.js} +1 -1
  505. package/studio/web/assets/{FloatingChat-BWImX5fA.js → FloatingChat-CoDW1ySS.js} +3 -3
  506. package/studio/web/assets/{apiToken-DN0nmDsq.js → apiToken-Bwk5BLXW.js} +1 -1
  507. package/studio/web/assets/{applications-kSxVoyeU.js → applications-DHxGi7JH.js} +1 -1
  508. package/studio/web/assets/{cssMode-C1JeufH5.js → cssMode-s0cWI-_M.js} +1 -1
  509. package/studio/web/assets/{editor-qoo9CrGO.js → editor-DNcRHK54.js} +1 -1
  510. package/studio/web/assets/{html-Dt4IIy04.js → html-Bdssedlg.js} +1 -1
  511. package/studio/web/assets/{htmlMode-DXgKKr4C.js → htmlMode-CoDlJ3fw.js} +1 -1
  512. package/studio/web/assets/{index-6onkYFOG.js → index-D6sxmFLR.js} +5 -5
  513. package/studio/web/assets/{index.lazy-BrCFnpNJ.js → index.lazy-tmU5BS8s.js} +1 -1
  514. package/studio/web/assets/{javascript-DNCQGUBc.js → javascript-B8meVSTH.js} +1 -1
  515. package/studio/web/assets/{jsonMode-CR6HWruP.js → jsonMode-DpIPd35T.js} +1 -1
  516. package/studio/web/assets/{languageServices-BM4fI4rS.js → languageServices-C_5FMJzQ.js} +1 -1
  517. package/studio/web/assets/{lspLanguageFeatures-DSa1ttcD.js → lspLanguageFeatures-BIzNBzPK.js} +1 -1
  518. package/studio/web/assets/{notifications-BHXLnh6x.js → notifications-CQf18QKb.js} +1 -1
  519. package/studio/web/assets/{notifications-CUmtIA6z.js → notifications-CvZivSbh.js} +1 -1
  520. package/studio/web/assets/{profile-8BeFSF3j.js → profile-DdOwtntb.js} +1 -1
  521. package/studio/web/assets/{regions-C8qR0HhD.js → regions-n69fwagr.js} +1 -1
  522. package/studio/web/assets/{register-B4n5i0SD.js → register-PfWTCXWB.js} +2 -2
  523. package/studio/web/assets/{setComponentFile-g0_B0lgX.js → setComponentFile-Bg6O7X0S.js} +1 -1
  524. package/studio/web/assets/{setup-B0CTj_Q5.js → setup-CUx_aUDl.js} +2 -2
  525. package/studio/web/assets/{status-C6Yib7-K.js → status-D7BVKqX9.js} +1 -1
  526. package/studio/web/assets/{toggleHighContrast-Dgta7bVi.js → toggleHighContrast-DBSyXzMr.js} +1 -1
  527. package/studio/web/assets/{tsMode-CH_jHvU-.js → tsMode-BByKCjBS.js} +1 -1
  528. package/studio/web/assets/{typescript-Co9LCXd5.js → typescript-DDLnLpw9.js} +1 -1
  529. package/studio/web/assets/{useEntityRestURL-wKC8NsC_.js → useEntityRestURL-31CHGaHk.js} +1 -1
  530. package/studio/web/assets/{workers-CWeLxCXA.js → workers-pR3jRY9D.js} +1 -1
  531. package/studio/web/assets/{xml-BadC-0Rk.js → xml-2iRnMhQO.js} +1 -1
  532. package/studio/web/assets/{yaml-BiUfxPbC.js → yaml-Bf92gJpd.js} +1 -1
  533. package/studio/web/index.html +1 -1
  534. package/upgrade/directives/5-3-0.ts +132 -0
  535. package/upgrade/directives/directivesController.ts +2 -1
  536. package/utility/OperationFunctionCaller.ts +2 -1
  537. package/utility/common_utils.ts +30 -5
  538. package/utility/componentNames.ts +12 -0
  539. package/utility/environment/environmentManager.ts +3 -7
  540. package/utility/environment/systemInformation.ts +7 -0
  541. package/utility/errors/commonErrors.ts +4 -0
  542. package/utility/errors/hdbError.ts +29 -0
  543. package/utility/hdbTerms.ts +17 -0
  544. package/utility/logging/harper_logger.ts +87 -14
  545. package/utility/logging/logRotator.ts +72 -45
  546. package/utility/nodeIdentity.ts +45 -0
  547. package/utility/npmUtilities.ts +10 -8
  548. package/utility/operationPermissions.ts +18 -1
  549. package/utility/operation_authorization.ts +231 -42
  550. package/utility/watchPath.ts +63 -0
  551. package/utility/watcherFallback.ts +270 -0
  552. package/validation/configValidator.ts +209 -72
  553. package/validation/installValidator.ts +15 -0
  554. package/validation/validationWrapper.ts +18 -4
@@ -0,0 +1,358 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS = void 0;
37
+ exports.rebaseLongLivedTransactionReports = rebaseLongLivedTransactionReports;
38
+ exports.getReportThresholdMs = getReportThresholdMs;
39
+ exports.runLongLivedTransactionSweep = runLongLivedTransactionSweep;
40
+ exports.startLongLivedTransactionReporting = startLongLivedTransactionReporting;
41
+ exports.createLongLivedHolderReportBudget = createLongLivedHolderReportBudget;
42
+ exports.finishLongLivedHolderReports = finishLongLivedHolderReports;
43
+ exports.reportLongLivedHolder = reportLongLivedHolder;
44
+ exports.describeHolderCandidates = describeHolderCandidates;
45
+ exports.setRegistryStatusForTests = setRegistryStatusForTests;
46
+ exports.resetLongLivedTransactionReportsForTests = resetLongLivedTransactionReportsForTests;
47
+ const node_worker_threads_1 = require("node:worker_threads");
48
+ const node_path_1 = require("node:path");
49
+ const rocksdb_js_1 = require("@harperfast/rocksdb-js");
50
+ const logger_ts_1 = require("../utility/logging/logger.js");
51
+ const hdbTerms_ts_1 = require("../utility/hdbTerms.js");
52
+ const envMngr = __importStar(require("../utility/environment/environmentManager.js"));
53
+ const common_utils_ts_1 = require("../utility/common_utils.js");
54
+ const DEFAULT_REPORT_THRESHOLD_MS = 300000;
55
+ const SWEEP_INTERVAL_MS = 60000;
56
+ // One line per over-age handle would, against a large leak, block the main thread's socket routing
57
+ // for as long as it took to format them. The per-handle backoff below rotates the cap over the whole
58
+ // set across passes, so every holder is still named eventually.
59
+ exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS = 10;
60
+ const MAX_HOLDER_CANDIDATES = 3;
61
+ // The sweep prunes against the handles it just enumerated; the attribution map has no such
62
+ // enumeration, so its entries expire instead. Far longer than a sweep interval, so a still-live
63
+ // holder keeps its backoff.
64
+ const ATTRIBUTION_STATE_TTL_MS = 3600000;
65
+ // The prune is O(map) and the monitor calls reportLongLivedHolder once per over-threshold transaction
66
+ // per tick, so pruning per call is O(N^2) in exactly the leak this reporting exists to describe.
67
+ const ATTRIBUTION_PRUNE_INTERVAL_MS = 60000;
68
+ let registryStatusFn = typeof rocksdb_js_1.registryStatus === 'function' ? rocksdb_js_1.registryStatus : undefined;
69
+ const sweepReports = new Map();
70
+ const attributionReports = new Map();
71
+ let sweepTimer;
72
+ let invalidThresholdWarned = false;
73
+ let missingDetailsWarned = false;
74
+ let lastAttributionPruneAt = 0;
75
+ let thresholdInEffectMs = -1;
76
+ function reportKey(databasePath, nativeId, openedAt) {
77
+ return `${databasePath ?? '?'} ${nativeId}${openedAt == null ? '' : ` ${openedAt}`}`;
78
+ }
79
+ /**
80
+ * Record this observation of a handle and return its report state. A shrinking age means the id was
81
+ * reused by a reopened descriptor, so the previous holder's backoff must not suppress the new one.
82
+ */
83
+ function observeHandle(reports, key, ageMs, thresholdMs) {
84
+ let state = reports.get(key);
85
+ if (state && ageMs < state.lastAgeMs)
86
+ state = undefined;
87
+ if (!state) {
88
+ state = { nextReportAgeMs: thresholdMs, lastAgeMs: ageMs, touchedAt: 0 };
89
+ reports.set(key, state);
90
+ }
91
+ state.lastAgeMs = ageMs;
92
+ state.touchedAt = Date.now();
93
+ return state;
94
+ }
95
+ /**
96
+ * Drop the accrued backoff when the configured threshold changes, so a handle already under
97
+ * observation is re-measured against the new one. Without this, `nextReportAgeMs` keeps whatever it
98
+ * was given at first observation: lowering the threshold during an incident would not bring a
99
+ * silent handle's first report forward, and raising it would not quiet one. Reporting each live
100
+ * holder once more at the new threshold is what an operator who just changed it is asking for.
101
+ */
102
+ function rebaseIfThresholdChanged(thresholdMs) {
103
+ if (thresholdMs === thresholdInEffectMs)
104
+ return;
105
+ thresholdInEffectMs = thresholdMs;
106
+ sweepReports.clear();
107
+ attributionReports.clear();
108
+ }
109
+ /**
110
+ * Apply a live threshold at the start of every reporting pass, including one that finds no eligible
111
+ * holder. Otherwise a threshold raised above a holder's age leaves its old attribution backoff in
112
+ * place when the threshold is lowered again.
113
+ */
114
+ function rebaseLongLivedTransactionReports(thresholdMs) {
115
+ rebaseIfThresholdChanged(thresholdMs);
116
+ }
117
+ /**
118
+ * Push this handle's next report out to twice its current age, so one held for hours produces a
119
+ * handful of lines rather than one per pass. Called only where a line was actually emitted: advancing
120
+ * it for a handle the per-pass cap skipped would silence that handle without ever naming it.
121
+ */
122
+ function markReported(state, ageMs) {
123
+ state.nextReportAgeMs = ageMs * 2;
124
+ }
125
+ /**
126
+ * How old a native transaction handle must be before it is reported, in ms; 0 disables every surface
127
+ * here. Read per pass rather than cached so a live config reload takes effect. A value that cannot
128
+ * be a duration falls back to the default instead of silently disabling reporting.
129
+ */
130
+ function getReportThresholdMs() {
131
+ const configured = envMngr.get(hdbTerms_ts_1.CONFIG_PARAMS.STORAGE_LONGTRANSACTIONREPORTTHRESHOLD);
132
+ if (configured == null)
133
+ return DEFAULT_REPORT_THRESHOLD_MS;
134
+ // convertToMS returns 0 for anything that is neither string nor number, which YAML hands us for
135
+ // `yes`/`no` (booleans) and for an object left by a config merge — indistinguishable from the
136
+ // documented 0 that disables reporting, so it would silently switch off what the operator configured.
137
+ const ms = typeof configured === 'string' || typeof configured === 'number' ? (0, common_utils_ts_1.convertToMS)(configured) : NaN;
138
+ if (ms === 0)
139
+ return 0;
140
+ if (!Number.isFinite(ms) || ms < 0) {
141
+ if (!invalidThresholdWarned) {
142
+ invalidThresholdWarned = true;
143
+ logger_ts_1.logger.warn?.(`Invalid storage.longTransactionReportThreshold "${configured}"; using default ${DEFAULT_REPORT_THRESHOLD_MS}ms`);
144
+ }
145
+ return DEFAULT_REPORT_THRESHOLD_MS;
146
+ }
147
+ return ms;
148
+ }
149
+ /**
150
+ * Report every native transaction handle in the process-global rocksdb-js registry that has been open
151
+ * past the threshold — including handles no `DatabaseTransaction` owns, which is the one class of
152
+ * holder no other surface can see (harper#2471). The registry spans worker threads, so this runs on
153
+ * the main thread only; a per-thread sweep would report each handle once per worker.
154
+ */
155
+ function runLongLivedTransactionSweep() {
156
+ try {
157
+ const thresholdMs = getReportThresholdMs();
158
+ rebaseLongLivedTransactionReports(thresholdMs);
159
+ if (thresholdMs === 0 || !registryStatusFn)
160
+ return;
161
+ const status = registryStatusFn();
162
+ const seen = new Set();
163
+ const due = [];
164
+ let missingDetails = false;
165
+ for (const database of status) {
166
+ const details = database.transactionDetails;
167
+ if (!details) {
168
+ missingDetails = true;
169
+ continue;
170
+ }
171
+ for (const handle of details) {
172
+ if (handle.ageMs < thresholdMs)
173
+ continue;
174
+ const key = reportKey(database.path, handle.id);
175
+ seen.add(key);
176
+ const state = observeHandle(sweepReports, key, handle.ageMs, thresholdMs);
177
+ if (handle.ageMs >= state.nextReportAgeMs)
178
+ due.push({ path: database.path, id: handle.id, ageMs: handle.ageMs, state });
179
+ }
180
+ }
181
+ for (const key of sweepReports.keys())
182
+ if (!seen.has(key))
183
+ sweepReports.delete(key);
184
+ if (missingDetails && !missingDetailsWarned) {
185
+ missingDetailsWarned = true;
186
+ logger_ts_1.logger.warn?.('Long-lived transaction reporting is degraded: the installed @harperfast/rocksdb-js does not expose registryStatus().transactionDetails (requires 2.8.0)');
187
+ }
188
+ if (due.length === 0)
189
+ return;
190
+ due.sort((a, b) => b.ageMs - a.ageMs);
191
+ for (const handle of due.slice(0, exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS)) {
192
+ markReported(handle.state, handle.ageMs);
193
+ logger_ts_1.logger.warn?.(`Long-lived RocksDB transaction handle: id ${handle.id} has been open for ${(0, common_utils_ts_1.prettyDuration)(handle.ageMs)} on database ${handle.path ?? '?'}. ` +
194
+ `A handle this old can hold write intents that park other writers' commits, and may pin a read snapshot that blocks version reclamation.`);
195
+ }
196
+ if (due.length > exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS) {
197
+ logger_ts_1.logger.warn?.(`${due.length - exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS} further RocksDB transaction handle(s) are open past the ${(0, common_utils_ts_1.prettyDuration)(thresholdMs)} reporting threshold and were not listed individually.`);
198
+ }
199
+ }
200
+ catch (error) {
201
+ logger_ts_1.logger.error?.('Error sweeping for long-lived transaction handles', error);
202
+ }
203
+ }
204
+ /**
205
+ * Start the periodic sweep. Armed unconditionally on the main thread — the pass itself honors a live
206
+ * threshold change, including one that disables it — and idempotent because the thread startup path
207
+ * that calls it can run more than once.
208
+ */
209
+ function startLongLivedTransactionReporting() {
210
+ if (!node_worker_threads_1.isMainThread || sweepTimer)
211
+ return;
212
+ if (!registryStatusFn) {
213
+ logger_ts_1.logger.debug?.('Long-lived transaction reporting unavailable; @harperfast/rocksdb-js exposes no registryStatus()');
214
+ return;
215
+ }
216
+ sweepTimer = setInterval(runLongLivedTransactionSweep, SWEEP_INTERVAL_MS).unref();
217
+ }
218
+ function createLongLivedHolderReportBudget(thresholdMs) {
219
+ return { remaining: exports.MAX_LONG_LIVED_TRANSACTION_REPORTS_PER_PASS, skipped: 0, thresholdMs };
220
+ }
221
+ function finishLongLivedHolderReports(reportBudget) {
222
+ if (reportBudget.skipped === 0)
223
+ return;
224
+ try {
225
+ logger_ts_1.logger.warn?.(`${reportBudget.skipped} further Harper transaction holder(s) are open past the ${(0, common_utils_ts_1.prettyDuration)(reportBudget.thresholdMs)} reporting threshold and were deferred.`);
226
+ }
227
+ catch { }
228
+ }
229
+ /**
230
+ * Report a handle this thread owns, with the attribution the registry sweep cannot supply. The native
231
+ * id is the join key between the two: the sweep names an id, this names who holds it and which state
232
+ * kept the open-transaction monitor from reaping it (harper#2471). Never throws — the monitor
233
+ * interval that calls it has no handler.
234
+ */
235
+ function reportLongLivedHolder(holder, reportBudget) {
236
+ try {
237
+ if (!registryStatusFn)
238
+ return;
239
+ const thresholdMs = reportBudget?.thresholdMs ?? getReportThresholdMs();
240
+ rebaseLongLivedTransactionReports(thresholdMs);
241
+ if (thresholdMs === 0)
242
+ return;
243
+ const now = Date.now();
244
+ if (now - lastAttributionPruneAt >= ATTRIBUTION_PRUNE_INTERVAL_MS) {
245
+ lastAttributionPruneAt = now;
246
+ const expiredBefore = now - ATTRIBUTION_STATE_TTL_MS;
247
+ for (const [key, state] of attributionReports)
248
+ if (state.touchedAt < expiredBefore)
249
+ attributionReports.delete(key);
250
+ }
251
+ const state = observeHandle(attributionReports, reportKey(holder.databasePath, holder.nativeId, holder.openedAt), holder.ageMs, thresholdMs);
252
+ if (holder.ageMs < state.nextReportAgeMs)
253
+ return;
254
+ if (reportBudget && reportBudget.remaining <= 0) {
255
+ reportBudget.skipped++;
256
+ return;
257
+ }
258
+ markReported(state, holder.ageMs);
259
+ if (reportBudget)
260
+ reportBudget.remaining--;
261
+ const table = holder.tableName ? `.${holder.tableName}` : '';
262
+ logger_ts_1.logger.warn?.(`Harper transaction has held RocksDB transaction ${holder.nativeId} for ${(0, common_utils_ts_1.prettyDuration)(holder.ageMs)} ` +
263
+ `on thread ${node_worker_threads_1.threadId}, database ${holder.databaseName ?? '?'}${table} (${holder.databasePath ?? '?'}), ` +
264
+ `holding ${holder.countPendingWrites()} staged write(s), state: ${holder.states.join('+')}` +
265
+ (holder.timeoutBudget ? `, open-transaction budget ${holder.timeoutBudget}ms` : '') +
266
+ (holder.startedFrom?.resourceName
267
+ ? `, started from ${holder.startedFrom.resourceName}${holder.startedFrom.method ? '.' + holder.startedFrom.method : ''}`
268
+ : '') +
269
+ '. It is not being reaped by the open-transaction monitor; the state tells you why.');
270
+ }
271
+ catch (error) {
272
+ logger_ts_1.logger.debug?.('Failed to report a long-lived transaction holder', error);
273
+ }
274
+ }
275
+ /**
276
+ * The live handles that could be holding the write intent a stuck commit is parked on, as a sentence
277
+ * to append to that commit's log. A handle on another database is offered too, labelled with its path:
278
+ * the verification table is one process-global slot array whose hash mixes in the database id, so a
279
+ * holder in `system` or `oauth` collides with — and parks — a `data` commit at the same rate two `data`
280
+ * keys do. Rank puts the stuck commit's own database first, then age. Age only ranks: a coordinated
281
+ * retry parks on whichever transaction holds the slot when the commit reaches it, which can be younger
282
+ * than the commit itself, so filtering by age could drop the real holder.
283
+ * Returns '' rather than throwing — the caller's own 503 must survive a failure here.
284
+ */
285
+ function describeHolderCandidates(databasePath, excludeNativeId) {
286
+ if (!databasePath || !registryStatusFn)
287
+ return '';
288
+ try {
289
+ if (getReportThresholdMs() === 0)
290
+ return '';
291
+ const target = (0, node_path_1.resolve)(databasePath);
292
+ const candidates = [];
293
+ let targetSeen = false;
294
+ let targetHasDetails = false;
295
+ for (const database of registryStatusFn()) {
296
+ // An entry with no path can never be the target, and resolve() would throw on it — which,
297
+ // inside this loop, would drop the candidate list for every database rather than just this one.
298
+ const sameDatabase = database.path != null && (0, node_path_1.resolve)(database.path) === target;
299
+ const details = database.transactionDetails;
300
+ if (sameDatabase) {
301
+ targetSeen = true;
302
+ if (details)
303
+ targetHasDetails = true;
304
+ }
305
+ if (!details)
306
+ continue;
307
+ for (const handle of details)
308
+ if (!sameDatabase || handle.id !== excludeNativeId)
309
+ candidates.push({ id: handle.id, ageMs: handle.ageMs, sameDatabase, path: database.path });
310
+ }
311
+ if (!targetHasDetails) {
312
+ // A database with no other handles is normal; no entry at all means the join between a store's
313
+ // path and the registry's path has drifted, which is the one worth telling an operator apart.
314
+ logger_ts_1.logger.debug?.(targetSeen
315
+ ? `Registry entry for ${target} exposes no transactionDetails; only other databases' handles can be offered as holder candidates for its stuck commit`
316
+ : `No registry entry for ${target}; only other databases' handles can be offered as holder candidates for its stuck commit`);
317
+ }
318
+ if (candidates.length === 0)
319
+ return '';
320
+ candidates.sort((a, b) => Number(b.sameDatabase) - Number(a.sameDatabase) || b.ageMs - a.ageMs);
321
+ const shortlist = candidates.slice(0, MAX_HOLDER_CANDIDATES);
322
+ // Ranking this database first and then capping can bury the one candidate the cross-database
323
+ // search exists to surface: a busy database routinely has MAX_HOLDER_CANDIDATES handles of its
324
+ // own, so a foreign holder would only ever appear inside the "and N more" count. Give the oldest
325
+ // one the last slot instead.
326
+ if (shortlist.length === MAX_HOLDER_CANDIDATES && shortlist.every((candidate) => candidate.sameDatabase)) {
327
+ const foreign = candidates.find((candidate) => !candidate.sameDatabase);
328
+ if (foreign)
329
+ shortlist[MAX_HOLDER_CANDIDATES - 1] = foreign;
330
+ }
331
+ const named = shortlist
332
+ .map((candidate) => `${candidate.id} (open ${(0, common_utils_ts_1.prettyDuration)(candidate.ageMs)}${candidate.sameDatabase ? '' : ` on ${candidate.path ?? '?'}`})`)
333
+ .join(', ');
334
+ return (` Live transaction handles, any of which could hold the write intent this commit is parked on ` +
335
+ `(the verification table is one process-global slot array, so a handle on another database can hold it), ` +
336
+ `this database first, oldest first: ${named}` +
337
+ (candidates.length > MAX_HOLDER_CANDIDATES ? `, and ${candidates.length - MAX_HOLDER_CANDIDATES} more.` : '.'));
338
+ }
339
+ catch {
340
+ return '';
341
+ }
342
+ }
343
+ function setRegistryStatusForTests(fn) {
344
+ registryStatusFn = fn;
345
+ }
346
+ function resetLongLivedTransactionReportsForTests() {
347
+ sweepReports.clear();
348
+ attributionReports.clear();
349
+ invalidThresholdWarned = false;
350
+ missingDetailsWarned = false;
351
+ lastAttributionPruneAt = 0;
352
+ thresholdInEffectMs = -1;
353
+ if (sweepTimer) {
354
+ clearInterval(sweepTimer);
355
+ sweepTimer = undefined;
356
+ }
357
+ }
358
+ //# sourceMappingURL=longLivedTransactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"longLivedTransactions.js","sourceRoot":"","sources":["../../resources/longLivedTransactions.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiFA,8EAEC;AAgBD,oDAkBC;AAQD,oEAgDC;AAOD,gFAOC;AAwBD,8EAEC;AAED,oEAOC;AAQD,sDAwCC;AAYD,4DA4DC;AAED,8DAEC;AAED,4FAWC;AAvWD,6DAA6D;AAC7D,yCAAoC;AACpC,uDAAwD;AACxD,4DAAsD;AACtD,wDAAuD;AACvD,sFAAwE;AACxE,gEAAyE;AAEzE,MAAM,2BAA2B,GAAG,MAAM,CAAC;AAC3C,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,mGAAmG;AACnG,qGAAqG;AACrG,gEAAgE;AACnD,QAAA,2CAA2C,GAAG,EAAE,CAAC;AAC9D,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,2FAA2F;AAC3F,gGAAgG;AAChG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H,CAAC,SAAS,EAAE,EAAE,CACb,GAAG,SAAS,CAAC,EAAE,UAAU,IAAA,gCAAc,EAAC,SAAS,CAAC,KAAK,CAAC,GAAG,SAAS,CAAC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,SAAS,CAAC,IAAI,IAAI,GAAG,EAAE,GAAG,CAC3H;aACA,IAAI,CAAC,IAAI,CAAC,CAAC;QACb,OAAO,CACN,+FAA+F;YAC/F,0GAA0G;YAC1G,sCAAsC,KAAK,EAAE;YAC7C,CAAC,UAAU,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC,CAAC,SAAS,UAAU,CAAC,MAAM,GAAG,qBAAqB,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAC9G,CAAC;IACH,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,EAAE,CAAC;IACX,CAAC;AACF,CAAC;AAED,SAAgB,yBAAyB,CAAC,EAAqB;IAC9D,gBAAgB,GAAG,EAAE,CAAC;AACvB,CAAC;AAED,SAAgB,wCAAwC;IACvD,YAAY,CAAC,KAAK,EAAE,CAAC;IACrB,kBAAkB,CAAC,KAAK,EAAE,CAAC;IAC3B,sBAAsB,GAAG,KAAK,CAAC;IAC/B,oBAAoB,GAAG,KAAK,CAAC;IAC7B,sBAAsB,GAAG,CAAC,CAAC;IAC3B,mBAAmB,GAAG,CAAC,CAAC,CAAC;IACzB,IAAI,UAAU,EAAE,CAAC;QAChB,aAAa,CAAC,UAAU,CAAC,CAAC;QAC1B,UAAU,GAAG,SAAS,CAAC;IACxB,CAAC;AACF,CAAC"}
@@ -18,10 +18,36 @@ import type { DefineBackendSpec, ModelBackend } from './types.ts';
18
18
  * step) lands in Phase 2 alongside the first real backend.
19
19
  */
20
20
  type ModelKind = 'embedding' | 'generative';
21
+ /** A registration a factory made during construction, deferred to the caller. */
22
+ export interface CapturedInstall {
23
+ kind: ModelKind;
24
+ logicalName: string;
25
+ backend: ModelBackend;
26
+ }
21
27
  /** Map `logicalName` to a backend for embedding calls. Re-set replaces. */
22
28
  export declare function setEmbedding(logicalName: string, backend: ModelBackend): void;
23
29
  /** Map `logicalName` to a backend for generative calls. Re-set replaces. */
24
30
  export declare function setGenerative(logicalName: string, backend: ModelBackend): void;
31
+ /**
32
+ * Build a backend through its normal registration path but return it instead of installing it, so a
33
+ * config reload can install it conditionally. A scratch logical name would be briefly visible
34
+ * through `listBackends`, which backs the public `GET /v1/models`.
35
+ */
36
+ export declare function constructBackend(kind: ModelKind, logicalName: string, register: () => void | Promise<void>): Promise<{
37
+ backend?: ModelBackend;
38
+ extras: CapturedInstall[];
39
+ }>;
40
+ /**
41
+ * Replace `logicalName`'s backend for `kind` only if it is still `expected`. A plain `set` is atomic
42
+ * but unconditional, so concurrent writers resolve by arrival order rather than by which value is
43
+ * newer. A caller that loses the swap must re-derive from current state rather than overwrite.
44
+ */
45
+ export declare function replaceIfCurrent(kind: ModelKind, logicalName: string, expected: ModelBackend | undefined, next: ModelBackend): boolean;
46
+ /**
47
+ * Remove `logicalName`'s backend for `kind` only if it is still `expected`, returning whether it was
48
+ * removed. Withdrawing a credential must not delete a slot another writer has since taken over.
49
+ */
50
+ export declare function removeIfCurrent(kind: ModelKind, logicalName: string, expected: ModelBackend | undefined): boolean;
25
51
  /** Non-throwing lookup of the backend mapped to `logicalName` for `kind`, or `undefined`. Used by the router to assemble + filter candidate lists without exceptions. */
26
52
  export declare function getBackend(kind: ModelKind, logicalName: string): ModelBackend | undefined;
27
53
  /**
@@ -3,6 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ModelBackendRegistrationError = exports.ModelBackendNotFoundError = void 0;
4
4
  exports.setEmbedding = setEmbedding;
5
5
  exports.setGenerative = setGenerative;
6
+ exports.constructBackend = constructBackend;
7
+ exports.replaceIfCurrent = replaceIfCurrent;
8
+ exports.removeIfCurrent = removeIfCurrent;
6
9
  exports.getBackend = getBackend;
7
10
  exports.listBackends = listBackends;
8
11
  exports.resolveEmbedding = resolveEmbedding;
@@ -10,16 +13,71 @@ exports.resolveGenerative = resolveGenerative;
10
13
  exports.registerBackend = registerBackend;
11
14
  exports.defineBackend = defineBackend;
12
15
  exports.clearRegistry = clearRegistry;
16
+ const node_async_hooks_1 = require("node:async_hooks");
13
17
  const hdbError_ts_1 = require("../../utility/errors/hdbError.js");
14
18
  const embedding = new Map();
15
19
  const generative = new Map();
20
+ // Async-context scoped: a module-global slot would divert unrelated registrations and collide
21
+ // concurrent constructions.
22
+ const captureScope = new node_async_hooks_1.AsyncLocalStorage();
23
+ function install(kind, logicalName, backend) {
24
+ const slot = captureScope.getStore();
25
+ if (slot?.active) {
26
+ if (slot.kind === kind && slot.logicalName === logicalName)
27
+ slot.backend = backend;
28
+ else
29
+ slot.extras.push({ kind, logicalName, backend });
30
+ return;
31
+ }
32
+ (kind === 'embedding' ? embedding : generative).set(logicalName, backend);
33
+ }
16
34
  /** Map `logicalName` to a backend for embedding calls. Re-set replaces. */
17
35
  function setEmbedding(logicalName, backend) {
18
- embedding.set(logicalName, backend);
36
+ install('embedding', logicalName, backend);
19
37
  }
20
38
  /** Map `logicalName` to a backend for generative calls. Re-set replaces. */
21
39
  function setGenerative(logicalName, backend) {
22
- generative.set(logicalName, backend);
40
+ install('generative', logicalName, backend);
41
+ }
42
+ /**
43
+ * Build a backend through its normal registration path but return it instead of installing it, so a
44
+ * config reload can install it conditionally. A scratch logical name would be briefly visible
45
+ * through `listBackends`, which backs the public `GET /v1/models`.
46
+ */
47
+ async function constructBackend(kind, logicalName, register) {
48
+ const slot = { kind, logicalName, extras: [], active: true };
49
+ try {
50
+ await captureScope.run(slot, async () => {
51
+ await register();
52
+ });
53
+ }
54
+ finally {
55
+ slot.active = false;
56
+ }
57
+ return { backend: slot.backend, extras: slot.extras };
58
+ }
59
+ /**
60
+ * Replace `logicalName`'s backend for `kind` only if it is still `expected`. A plain `set` is atomic
61
+ * but unconditional, so concurrent writers resolve by arrival order rather than by which value is
62
+ * newer. A caller that loses the swap must re-derive from current state rather than overwrite.
63
+ */
64
+ function replaceIfCurrent(kind, logicalName, expected, next) {
65
+ const map = kind === 'embedding' ? embedding : generative;
66
+ if (map.get(logicalName) !== expected)
67
+ return false;
68
+ map.set(logicalName, next);
69
+ return true;
70
+ }
71
+ /**
72
+ * Remove `logicalName`'s backend for `kind` only if it is still `expected`, returning whether it was
73
+ * removed. Withdrawing a credential must not delete a slot another writer has since taken over.
74
+ */
75
+ function removeIfCurrent(kind, logicalName, expected) {
76
+ const map = kind === 'embedding' ? embedding : generative;
77
+ if (map.get(logicalName) !== expected)
78
+ return false;
79
+ map.delete(logicalName);
80
+ return true;
23
81
  }
24
82
  /** Non-throwing lookup of the backend mapped to `logicalName` for `kind`, or `undefined`. Used by the router to assemble + filter candidate lists without exceptions. */
25
83
  function getBackend(kind, logicalName) {
@@ -1 +1 @@
1
- {"version":3,"file":"backendRegistry.js","sourceRoot":"","sources":["../../../resources/models/backendRegistry.ts"],"names":[],"mappings":";;;AA2BA,oCAEC;AAGD,sCAEC;AAGD,gCAEC;AAOD,oCAGC;AAMD,4CAIC;AAMD,8CAIC;AAoBD,0CAuBC;AASD,sCA6BC;AA8BD,sCAGC;AAvLD,kEAA+D;AAuB/D,MAAM,SAAS,GAA8B,IAAI,GAAG,EAAE,CAAC;AACvD,MAAM,UAAU,GAA8B,IAAI,GAAG,EAAE,CAAC;AAExD,2EAA2E;AAC3E,SAAgB,YAAY,CAAC,WAAmB,EAAE,OAAqB;IACtE,SAAS,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACrC,CAAC;AAED,4EAA4E;AAC5E,SAAgB,aAAa,CAAC,WAAmB,EAAE,OAAqB;IACvE,UAAU,CAAC,GAAG,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAED,yKAAyK;AACzK,SAAgB,UAAU,CAAC,IAAe,EAAE,WAAmB;IAC9D,OAAO,CAAC,IAAI,KAAK,WAAW,CAAC,CAAC,CAAC,SA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,IAAI,EAAE,EAAE,CAAC;gBAC7C,IAAI,OAAO,EAAE,CAAC,EAAE,KAAK,QAAQ,IAAI,OAAO,EAAE,CAAC,IAAI,KAAK,QAAQ;oBAAE,SAAS,CAAC,IAAI,CAAC,EAAc,CAAC,CAAC;YAC9F,CAAC;QACF,CAAC;QACD,MAAM,MAAM,GACX,SAAS,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,CAAC;QACzF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;IACxC,CAAC,CAAC;AACH,CAAC;AAED,mDAAmD;AACnD,SAAgB,aAAa;IAC5B,SAAS,CAAC,KAAK,EAAE,CAAC;IAClB,UAAU,CAAC,KAAK,EAAE,CAAC;AACpB,CAAC;AAED,MAAa,yBAA0B,SAAQ,yBAAW;IACzD,0EAA0E;IAC1E,2EAA2E;IAC3E,YAAY,IAAe,EAAE,WAAmB;QAC/C,KAAK,CAAC,8BAA8B,IAAI,IAAI,WAAW,GAAG,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,2BAA2B,CAAC;IACzC,CAAC;CACD;AAPD,8DAOC;AAED,mFAAmF;AACnF,MAAa,6BAA8B,SAAQ,yBAAW;IAC7D,YAAY,OAAe;QAC1B,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,+BAA+B,CAAC;IAC7C,CAAC;CACD;AALD,sEAKC"}
@@ -1,3 +1,4 @@
1
+ import { RootConfigWatcher } from '../../config/RootConfigWatcher.ts';
1
2
  interface ModelEntry {
2
3
  backend?: string;
3
4
  host?: string;
@@ -20,7 +21,38 @@ interface RootConfig {
20
21
  /**
21
22
  * Populate the model registry from `rootConfig.models`. No-op if the block
22
23
  * is absent or empty. Idempotent within a process: each entry overwrites any
23
- * prior registration under the same logical name (registry uses `.set()`).
24
+ * prior registration under the same logical name.
24
25
  */
25
26
  export declare function bootstrapModels(rootConfig: RootConfig | undefined | null): Promise<void>;
27
+ /** Forget everything the projection installed. Test isolation only — never part of a reload. */
28
+ export declare function resetModelsProjection(): void;
29
+ /**
30
+ * Apply a `models:` block as a hot reload: changed entries are rebuilt through the same factories
31
+ * boot uses and swapped in atomically, removed entries stop serving, and programmatic
32
+ * registrations that overrode a config entry are left in place. Serialized and coalesced —
33
+ * concurrent calls settle on the latest block.
34
+ */
35
+ export declare function applyModelsConfig(models: ModelsConfig | undefined): Promise<void>;
36
+ /**
37
+ * Watch the root config file and hot-apply `models:` changes. Follows `harper_logger`'s
38
+ * root-config-watch pattern: one watcher per worker, each worker reprojecting its own registry.
39
+ *
40
+ * The watcher sees the FILE, but `HARPER_DEFAULT_CONFIG` / `HARPER_CONFIG` / `HARPER_SET_CONFIG`
41
+ * compose with it at boot — so if any of those names `models`, the file alone is not authoritative
42
+ * for the block and hot reload stays off, preserving boot semantics unchanged. (That is also the
43
+ * compatibility gate: an orchestrator still injecting models through `HARPER_SET_CONFIG` gets
44
+ * today's restart behavior; one that writes the file instead gets live reload.)
45
+ *
46
+ * Returns whether the watch is active.
47
+ */
48
+ export declare function startModelsConfigHotReload(options?: {
49
+ configFilePath?: string;
50
+ debounceMs?: number;
51
+ /** Test seam: invoked when a watcher snapshot is observed, before its settle timer is armed. */
52
+ onSnapshotObserved?: () => void;
53
+ /** Test seam: subscribe to this instance (caller-owned) instead of constructing or sharing. */
54
+ watcher?: RootConfigWatcher;
55
+ }): boolean;
56
+ /** Stop watching the config file. The current projection keeps serving. */
57
+ export declare function stopModelsConfigHotReload(): void;
26
58
  export {};