@harperfast/harper 5.0.30 → 5.1.0-beta.2

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 (1140) hide show
  1. package/README.md +11 -10
  2. package/agent/agent.ts +203 -0
  3. package/agent/loop.ts +205 -0
  4. package/agent/operations.ts +148 -0
  5. package/agent/session.ts +187 -0
  6. package/agent/tools/fsTools.ts +276 -0
  7. package/agent/tools/httpFetchTool.ts +112 -0
  8. package/agent/tools/scheduleTool.ts +68 -0
  9. package/agent/toolset.ts +43 -0
  10. package/agent/types.ts +85 -0
  11. package/bin/{BinObjects.js → BinObjects.ts} +4 -5
  12. package/bin/cliCredentials.ts +133 -0
  13. package/bin/cliOperations.ts +339 -0
  14. package/bin/copyDb.ts +10 -10
  15. package/bin/deployRenderer.ts +196 -0
  16. package/bin/{harper.js → harper.ts} +43 -19
  17. package/bin/{install.js → install.ts} +3 -3
  18. package/bin/lite.ts +2 -0
  19. package/bin/login.ts +134 -0
  20. package/bin/logout.ts +11 -0
  21. package/bin/mcp/client.ts +407 -0
  22. package/bin/mcp/doctor.ts +189 -0
  23. package/bin/mcp/index.ts +80 -0
  24. package/bin/mcp/options.ts +122 -0
  25. package/bin/mcp/printConfig.ts +89 -0
  26. package/bin/multipartBuilder.ts +74 -0
  27. package/bin/{restart.js → restart.ts} +27 -28
  28. package/bin/{run.js → run.ts} +41 -30
  29. package/bin/sseConsumer.ts +126 -0
  30. package/bin/{status.js → status.ts} +10 -10
  31. package/bin/{stop.js → stop.ts} +5 -5
  32. package/bin/upgrade.js +17 -24
  33. package/components/Application.ts +144 -18
  34. package/components/ApplicationScope.ts +2 -2
  35. package/components/ComponentV1.ts +2 -2
  36. package/components/EntryHandler.ts +159 -9
  37. package/components/OptionsWatcher.ts +75 -11
  38. package/components/Scope.ts +132 -18
  39. package/components/anthropic/index.ts +547 -0
  40. package/components/bedrock/index.ts +823 -0
  41. package/components/componentLoader.ts +64 -32
  42. package/components/deployLifecycle.ts +161 -0
  43. package/components/deploymentOperations.ts +173 -0
  44. package/components/deploymentRecorder.ts +427 -0
  45. package/components/deriveURLPath.ts +4 -4
  46. package/components/mcp/adapters/fastify.ts +87 -0
  47. package/components/mcp/adapters/harperHttp.ts +103 -0
  48. package/components/mcp/audit.ts +75 -0
  49. package/components/mcp/index.ts +134 -0
  50. package/components/mcp/jsonrpc.ts +134 -0
  51. package/components/mcp/lifecycle.ts +105 -0
  52. package/components/mcp/listChanged.ts +270 -0
  53. package/components/mcp/rateLimit.ts +217 -0
  54. package/components/mcp/resources.ts +607 -0
  55. package/components/mcp/session.ts +151 -0
  56. package/components/mcp/sessionRegistry.ts +140 -0
  57. package/components/mcp/toolRegistry.ts +294 -0
  58. package/components/mcp/tools/application.ts +761 -0
  59. package/components/mcp/tools/operations.ts +311 -0
  60. package/components/mcp/tools/schemas/derive.ts +356 -0
  61. package/components/mcp/tools/schemas/operationDescriptions.ts +241 -0
  62. package/components/mcp/tools/schemas/operations.ts +301 -0
  63. package/components/mcp/transport.ts +517 -0
  64. package/components/ollama/index.ts +316 -0
  65. package/components/openai/index.ts +563 -0
  66. package/components/operations.js +217 -60
  67. package/components/operationsValidation.js +12 -4
  68. package/components/packageComponent.ts +97 -29
  69. package/components/requestRestart.ts +17 -2
  70. package/components/status/crossThread.ts +14 -5
  71. package/components/status/errors.ts +1 -1
  72. package/config/RootConfigWatcher.ts +56 -2
  73. package/config/configUtils.js +29 -8
  74. package/config/harperConfigEnvVars.ts +1 -1
  75. package/config-root.schema.json +78 -4
  76. package/dataLayer/{CreateAttributeObject.js → CreateAttributeObject.ts} +4 -3
  77. package/dataLayer/{CreateTableObject.js → CreateTableObject.ts} +2 -1
  78. package/dataLayer/{DataLayerObjects.js → DataLayerObjects.ts} +17 -9
  79. package/dataLayer/{DeleteBeforeObject.js → DeleteBeforeObject.ts} +2 -1
  80. package/dataLayer/{DeleteObject.js → DeleteObject.ts} +3 -2
  81. package/dataLayer/{DropAttributeObject.js → DropAttributeObject.ts} +2 -1
  82. package/dataLayer/{GetBackupObject.js → GetBackupObject.ts} +3 -2
  83. package/dataLayer/{InsertObject.js → InsertObject.ts} +3 -2
  84. package/dataLayer/{ReadAuditLogObject.js → ReadAuditLogObject.ts} +3 -2
  85. package/dataLayer/{SQLSearch.js → SQLSearch.ts} +97 -43
  86. package/dataLayer/{SearchByConditionsObject.js → SearchByConditionsObject.ts} +5 -6
  87. package/dataLayer/{SearchByHashObject.js → SearchByHashObject.ts} +2 -1
  88. package/dataLayer/{SearchObject.js → SearchObject.ts} +2 -1
  89. package/dataLayer/{SqlSearchObject.js → SqlSearchObject.ts} +2 -1
  90. package/dataLayer/{UpdateObject.js → UpdateObject.ts} +3 -2
  91. package/dataLayer/{UpsertObject.js → UpsertObject.ts} +3 -2
  92. package/dataLayer/{bulkLoad.js → bulkLoad.ts} +40 -49
  93. package/dataLayer/{delete.js → delete.ts} +21 -26
  94. package/dataLayer/{export.js → export.ts} +22 -26
  95. package/dataLayer/{getBackup.js → getBackup.ts} +7 -9
  96. package/dataLayer/harperBridge/BridgeMethods.ts +102 -0
  97. package/dataLayer/harperBridge/ResourceBridge.ts +27 -26
  98. package/dataLayer/harperBridge/TableSizeObject.ts +1 -0
  99. package/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
  100. package/dataLayer/harperBridge/{harperBridge.js → harperBridge.ts} +3 -3
  101. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +8 -6
  102. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
  103. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
  104. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +6 -4
  105. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +5 -4
  106. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
  107. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +6 -5
  108. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +5 -4
  109. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
  110. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
  111. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
  112. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
  113. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +3 -2
  114. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
  115. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +10 -8
  116. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
  117. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +4 -3
  118. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
  119. package/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +6 -5
  120. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +2 -1
  121. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +3 -2
  122. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
  123. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +5 -4
  124. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +6 -3
  125. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.ts +1 -1
  126. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
  127. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
  128. package/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
  129. package/dataLayer/{hdbInfoController.js → hdbInfoController.ts} +20 -26
  130. package/dataLayer/{insert.js → insert.ts} +24 -24
  131. package/dataLayer/{readAuditLog.js → readAuditLog.ts} +8 -10
  132. package/dataLayer/{schema.js → schema.ts} +32 -44
  133. package/dataLayer/{schemaDescribe.js → schemaDescribe.ts} +23 -26
  134. package/dataLayer/{search.js → search.ts} +9 -15
  135. package/dataLayer/{transaction.js → transaction.ts} +2 -5
  136. package/dataLayer/{update.js → update.ts} +19 -22
  137. package/dist/agent/agent.d.ts +35 -0
  138. package/dist/agent/agent.js +175 -0
  139. package/dist/agent/agent.js.map +1 -0
  140. package/dist/agent/loop.d.ts +34 -0
  141. package/dist/agent/loop.js +176 -0
  142. package/dist/agent/loop.js.map +1 -0
  143. package/dist/agent/operations.d.ts +17 -0
  144. package/dist/agent/operations.js +137 -0
  145. package/dist/agent/operations.js.map +1 -0
  146. package/dist/agent/session.d.ts +36 -0
  147. package/dist/agent/session.js +182 -0
  148. package/dist/agent/session.js.map +1 -0
  149. package/dist/agent/tools/fsTools.d.ts +19 -0
  150. package/dist/agent/tools/fsTools.js +286 -0
  151. package/dist/agent/tools/fsTools.js.map +1 -0
  152. package/dist/agent/tools/httpFetchTool.d.ts +9 -0
  153. package/dist/agent/tools/httpFetchTool.js +116 -0
  154. package/dist/agent/tools/httpFetchTool.js.map +1 -0
  155. package/dist/agent/tools/scheduleTool.d.ts +22 -0
  156. package/dist/agent/tools/scheduleTool.js +54 -0
  157. package/dist/agent/tools/scheduleTool.js.map +1 -0
  158. package/dist/agent/toolset.d.ts +24 -0
  159. package/dist/agent/toolset.js +33 -0
  160. package/dist/agent/toolset.js.map +1 -0
  161. package/dist/agent/types.d.ts +75 -0
  162. package/dist/agent/types.js +10 -0
  163. package/dist/agent/types.js.map +1 -0
  164. package/dist/bin/BinObjects.d.ts +2 -2
  165. package/dist/bin/BinObjects.js +6 -3
  166. package/dist/bin/BinObjects.js.map +1 -1
  167. package/dist/bin/cliCredentials.d.ts +27 -0
  168. package/dist/bin/cliCredentials.js +130 -0
  169. package/dist/bin/cliCredentials.js.map +1 -0
  170. package/dist/bin/cliOperations.d.ts +7 -7
  171. package/dist/bin/cliOperations.js +251 -37
  172. package/dist/bin/cliOperations.js.map +1 -1
  173. package/dist/bin/copyDb.js +16 -16
  174. package/dist/bin/copyDb.js.map +1 -1
  175. package/dist/bin/deployRenderer.d.ts +47 -0
  176. package/dist/bin/deployRenderer.js +185 -0
  177. package/dist/bin/deployRenderer.js.map +1 -0
  178. package/dist/bin/harper.d.ts +2 -1
  179. package/dist/bin/harper.js +87 -26
  180. package/dist/bin/harper.js.map +1 -1
  181. package/dist/bin/install.d.ts +1 -1
  182. package/dist/bin/install.js +41 -4
  183. package/dist/bin/install.js.map +1 -1
  184. package/dist/bin/lite.js +3 -4
  185. package/dist/bin/lite.js.map +1 -1
  186. package/dist/bin/login.d.ts +4 -0
  187. package/dist/bin/login.js +123 -0
  188. package/dist/bin/login.js.map +1 -0
  189. package/dist/bin/logout.d.ts +4 -0
  190. package/dist/bin/logout.js +16 -0
  191. package/dist/bin/logout.js.map +1 -0
  192. package/dist/bin/mcp/client.d.ts +34 -0
  193. package/dist/bin/mcp/client.js +395 -0
  194. package/dist/bin/mcp/client.js.map +1 -0
  195. package/dist/bin/mcp/doctor.d.ts +11 -0
  196. package/dist/bin/mcp/doctor.js +193 -0
  197. package/dist/bin/mcp/doctor.js.map +1 -0
  198. package/dist/bin/mcp/index.d.ts +10 -0
  199. package/dist/bin/mcp/index.js +81 -0
  200. package/dist/bin/mcp/index.js.map +1 -0
  201. package/dist/bin/mcp/options.d.ts +33 -0
  202. package/dist/bin/mcp/options.js +113 -0
  203. package/dist/bin/mcp/options.js.map +1 -0
  204. package/dist/bin/mcp/printConfig.d.ts +14 -0
  205. package/dist/bin/mcp/printConfig.js +85 -0
  206. package/dist/bin/mcp/printConfig.js.map +1 -0
  207. package/dist/bin/multipartBuilder.d.ts +26 -0
  208. package/dist/bin/multipartBuilder.js +55 -0
  209. package/dist/bin/multipartBuilder.js.map +1 -0
  210. package/dist/bin/restart.d.ts +3 -2
  211. package/dist/bin/restart.js +82 -45
  212. package/dist/bin/restart.js.map +1 -1
  213. package/dist/bin/run.d.ts +13 -9
  214. package/dist/bin/run.js +111 -65
  215. package/dist/bin/run.js.map +1 -1
  216. package/dist/bin/sseConsumer.d.ts +24 -0
  217. package/dist/bin/sseConsumer.js +127 -0
  218. package/dist/bin/sseConsumer.js.map +1 -0
  219. package/dist/bin/status.d.ts +1 -1
  220. package/dist/bin/status.js +48 -11
  221. package/dist/bin/status.js.map +1 -1
  222. package/dist/bin/stop.d.ts +1 -1
  223. package/dist/bin/stop.js +43 -6
  224. package/dist/bin/stop.js.map +1 -1
  225. package/dist/bin/upgrade.js +14 -22
  226. package/dist/bin/upgrade.js.map +1 -1
  227. package/dist/components/Application.d.ts +29 -17
  228. package/dist/components/Application.js +134 -28
  229. package/dist/components/Application.js.map +1 -1
  230. package/dist/components/ApplicationScope.js +2 -2
  231. package/dist/components/ComponentV1.d.ts +1 -1
  232. package/dist/components/ComponentV1.js +5 -5
  233. package/dist/components/ComponentV1.js.map +1 -1
  234. package/dist/components/EntryHandler.d.ts +26 -3
  235. package/dist/components/EntryHandler.js +153 -13
  236. package/dist/components/EntryHandler.js.map +1 -1
  237. package/dist/components/OptionsWatcher.d.ts +7 -2
  238. package/dist/components/OptionsWatcher.js +72 -10
  239. package/dist/components/OptionsWatcher.js.map +1 -1
  240. package/dist/components/Scope.d.ts +11 -6
  241. package/dist/components/Scope.js +112 -12
  242. package/dist/components/Scope.js.map +1 -1
  243. package/dist/components/anthropic/index.d.ts +40 -0
  244. package/dist/components/anthropic/index.js +428 -0
  245. package/dist/components/anthropic/index.js.map +1 -0
  246. package/dist/components/bedrock/index.d.ts +79 -0
  247. package/dist/components/bedrock/index.js +734 -0
  248. package/dist/components/bedrock/index.js.map +1 -0
  249. package/dist/components/componentLoader.d.ts +29 -0
  250. package/dist/components/componentLoader.js +65 -38
  251. package/dist/components/componentLoader.js.map +1 -1
  252. package/dist/components/deployLifecycle.d.ts +39 -0
  253. package/dist/components/deployLifecycle.js +156 -0
  254. package/dist/components/deployLifecycle.js.map +1 -0
  255. package/dist/components/deploymentOperations.d.ts +19 -0
  256. package/dist/components/deploymentOperations.js +185 -0
  257. package/dist/components/deploymentOperations.js.map +1 -0
  258. package/dist/components/deploymentRecorder.d.ts +97 -0
  259. package/dist/components/deploymentRecorder.js +425 -0
  260. package/dist/components/deploymentRecorder.js.map +1 -0
  261. package/dist/components/deriveURLPath.d.ts +2 -2
  262. package/dist/components/deriveURLPath.js +2 -2
  263. package/dist/components/deriveURLPath.js.map +1 -1
  264. package/dist/components/mcp/adapters/fastify.d.ts +35 -0
  265. package/dist/components/mcp/adapters/fastify.js +66 -0
  266. package/dist/components/mcp/adapters/fastify.js.map +1 -0
  267. package/dist/components/mcp/adapters/harperHttp.d.ts +38 -0
  268. package/dist/components/mcp/adapters/harperHttp.js +78 -0
  269. package/dist/components/mcp/adapters/harperHttp.js.map +1 -0
  270. package/dist/components/mcp/audit.d.ts +27 -0
  271. package/dist/components/mcp/audit.js +73 -0
  272. package/dist/components/mcp/audit.js.map +1 -0
  273. package/dist/components/mcp/index.d.ts +47 -0
  274. package/dist/components/mcp/index.js +109 -0
  275. package/dist/components/mcp/index.js.map +1 -0
  276. package/dist/components/mcp/jsonrpc.d.ts +71 -0
  277. package/dist/components/mcp/jsonrpc.js +93 -0
  278. package/dist/components/mcp/jsonrpc.js.map +1 -0
  279. package/dist/components/mcp/lifecycle.d.ts +69 -0
  280. package/dist/components/mcp/lifecycle.js +79 -0
  281. package/dist/components/mcp/lifecycle.js.map +1 -0
  282. package/dist/components/mcp/listChanged.d.ts +24 -0
  283. package/dist/components/mcp/listChanged.js +257 -0
  284. package/dist/components/mcp/listChanged.js.map +1 -0
  285. package/dist/components/mcp/rateLimit.d.ts +25 -0
  286. package/dist/components/mcp/rateLimit.js +226 -0
  287. package/dist/components/mcp/rateLimit.js.map +1 -0
  288. package/dist/components/mcp/resources.d.ts +90 -0
  289. package/dist/components/mcp/resources.js +526 -0
  290. package/dist/components/mcp/resources.js.map +1 -0
  291. package/dist/components/mcp/session.d.ts +36 -0
  292. package/dist/components/mcp/session.js +170 -0
  293. package/dist/components/mcp/session.js.map +1 -0
  294. package/dist/components/mcp/sessionRegistry.d.ts +63 -0
  295. package/dist/components/mcp/sessionRegistry.js +124 -0
  296. package/dist/components/mcp/sessionRegistry.js.map +1 -0
  297. package/dist/components/mcp/toolRegistry.d.ts +151 -0
  298. package/dist/components/mcp/toolRegistry.js +177 -0
  299. package/dist/components/mcp/toolRegistry.js.map +1 -0
  300. package/dist/components/mcp/tools/application.d.ts +72 -0
  301. package/dist/components/mcp/tools/application.js +660 -0
  302. package/dist/components/mcp/tools/application.js.map +1 -0
  303. package/dist/components/mcp/tools/operations.d.ts +23 -0
  304. package/dist/components/mcp/tools/operations.js +331 -0
  305. package/dist/components/mcp/tools/operations.js.map +1 -0
  306. package/dist/components/mcp/tools/schemas/derive.d.ts +50 -0
  307. package/dist/components/mcp/tools/schemas/derive.js +291 -0
  308. package/dist/components/mcp/tools/schemas/derive.js.map +1 -0
  309. package/dist/components/mcp/tools/schemas/operationDescriptions.d.ts +32 -0
  310. package/dist/components/mcp/tools/schemas/operationDescriptions.js +179 -0
  311. package/dist/components/mcp/tools/schemas/operationDescriptions.js.map +1 -0
  312. package/dist/components/mcp/tools/schemas/operations.d.ts +27 -0
  313. package/dist/components/mcp/tools/schemas/operations.js +299 -0
  314. package/dist/components/mcp/tools/schemas/operations.js.map +1 -0
  315. package/dist/components/mcp/transport.d.ts +38 -0
  316. package/dist/components/mcp/transport.js +467 -0
  317. package/dist/components/mcp/transport.js.map +1 -0
  318. package/dist/components/ollama/index.d.ts +46 -0
  319. package/dist/components/ollama/index.js +239 -0
  320. package/dist/components/ollama/index.js.map +1 -0
  321. package/dist/components/openai/index.d.ts +51 -0
  322. package/dist/components/openai/index.js +475 -0
  323. package/dist/components/openai/index.js.map +1 -0
  324. package/dist/components/operations.d.ts +6 -6
  325. package/dist/components/operations.js +205 -52
  326. package/dist/components/operations.js.map +1 -1
  327. package/dist/components/operationsValidation.d.ts +2 -2
  328. package/dist/components/operationsValidation.js +13 -4
  329. package/dist/components/operationsValidation.js.map +1 -1
  330. package/dist/components/packageComponent.d.ts +28 -6
  331. package/dist/components/packageComponent.js +87 -26
  332. package/dist/components/packageComponent.js.map +1 -1
  333. package/dist/components/requestRestart.d.ts +1 -0
  334. package/dist/components/requestRestart.js +12 -1
  335. package/dist/components/requestRestart.js.map +1 -1
  336. package/dist/components/status/crossThread.d.ts +5 -1
  337. package/dist/components/status/crossThread.js +12 -5
  338. package/dist/components/status/crossThread.js.map +1 -1
  339. package/dist/components/status/errors.js +7 -7
  340. package/dist/config/RootConfigWatcher.d.ts +3 -0
  341. package/dist/config/RootConfigWatcher.js +52 -1
  342. package/dist/config/RootConfigWatcher.js.map +1 -1
  343. package/dist/config/configUtils.js +31 -8
  344. package/dist/config/configUtils.js.map +1 -1
  345. package/dist/config/harperConfigEnvVars.js +1 -1
  346. package/dist/config/harperConfigEnvVars.js.map +1 -1
  347. package/dist/dataLayer/CreateAttributeObject.d.ts +3 -7
  348. package/dist/dataLayer/CreateAttributeObject.js +4 -3
  349. package/dist/dataLayer/CreateAttributeObject.js.map +1 -1
  350. package/dist/dataLayer/CreateTableObject.d.ts +2 -4
  351. package/dist/dataLayer/CreateTableObject.js +2 -1
  352. package/dist/dataLayer/CreateTableObject.js.map +1 -1
  353. package/dist/dataLayer/DataLayerObjects.d.ts +17 -16
  354. package/dist/dataLayer/DataLayerObjects.js +19 -5
  355. package/dist/dataLayer/DataLayerObjects.js.map +1 -1
  356. package/dist/dataLayer/DeleteBeforeObject.d.ts +3 -5
  357. package/dist/dataLayer/DeleteBeforeObject.js +2 -1
  358. package/dist/dataLayer/DeleteBeforeObject.js.map +1 -1
  359. package/dist/dataLayer/DeleteObject.d.ts +3 -7
  360. package/dist/dataLayer/DeleteObject.js +4 -3
  361. package/dist/dataLayer/DeleteObject.js.map +1 -1
  362. package/dist/dataLayer/DropAttributeObject.d.ts +2 -4
  363. package/dist/dataLayer/DropAttributeObject.js +2 -1
  364. package/dist/dataLayer/DropAttributeObject.js.map +1 -1
  365. package/dist/dataLayer/GetBackupObject.d.ts +3 -5
  366. package/dist/dataLayer/GetBackupObject.js +4 -3
  367. package/dist/dataLayer/GetBackupObject.js.map +1 -1
  368. package/dist/dataLayer/InsertObject.d.ts +3 -8
  369. package/dist/dataLayer/InsertObject.js +4 -3
  370. package/dist/dataLayer/InsertObject.js.map +1 -1
  371. package/dist/dataLayer/ReadAuditLogObject.d.ts +3 -7
  372. package/dist/dataLayer/ReadAuditLogObject.js +4 -3
  373. package/dist/dataLayer/ReadAuditLogObject.js.map +1 -1
  374. package/dist/dataLayer/SQLSearch.d.ts +68 -38
  375. package/dist/dataLayer/SQLSearch.js +140 -78
  376. package/dist/dataLayer/SQLSearch.js.map +1 -1
  377. package/dist/dataLayer/SearchByConditionsObject.d.ts +10 -58
  378. package/dist/dataLayer/SearchByConditionsObject.js +5 -7
  379. package/dist/dataLayer/SearchByConditionsObject.js.map +1 -1
  380. package/dist/dataLayer/SearchByHashObject.d.ts +3 -6
  381. package/dist/dataLayer/SearchByHashObject.js +2 -1
  382. package/dist/dataLayer/SearchByHashObject.js.map +1 -1
  383. package/dist/dataLayer/SearchObject.d.ts +3 -12
  384. package/dist/dataLayer/SearchObject.js +2 -1
  385. package/dist/dataLayer/SearchObject.js.map +1 -1
  386. package/dist/dataLayer/SqlSearchObject.d.ts +2 -4
  387. package/dist/dataLayer/SqlSearchObject.js +2 -1
  388. package/dist/dataLayer/SqlSearchObject.js.map +1 -1
  389. package/dist/dataLayer/UpdateObject.d.ts +3 -7
  390. package/dist/dataLayer/UpdateObject.js +4 -3
  391. package/dist/dataLayer/UpdateObject.js.map +1 -1
  392. package/dist/dataLayer/UpsertObject.d.ts +3 -7
  393. package/dist/dataLayer/UpsertObject.js +4 -3
  394. package/dist/dataLayer/UpsertObject.js.map +1 -1
  395. package/dist/dataLayer/bulkLoad.d.ts +4 -4
  396. package/dist/dataLayer/bulkLoad.js +122 -88
  397. package/dist/dataLayer/bulkLoad.js.map +1 -1
  398. package/dist/dataLayer/delete.d.ts +10 -11
  399. package/dist/dataLayer/delete.js +74 -39
  400. package/dist/dataLayer/delete.js.map +1 -1
  401. package/dist/dataLayer/export.d.ts +8 -8
  402. package/dist/dataLayer/export.js +90 -55
  403. package/dist/dataLayer/export.js.map +1 -1
  404. package/dist/dataLayer/getBackup.d.ts +4 -3
  405. package/dist/dataLayer/getBackup.js +43 -11
  406. package/dist/dataLayer/getBackup.js.map +1 -1
  407. package/dist/dataLayer/harperBridge/BridgeMethods.d.ts +39 -21
  408. package/dist/dataLayer/harperBridge/BridgeMethods.js +41 -20
  409. package/dist/dataLayer/harperBridge/BridgeMethods.js.map +1 -1
  410. package/dist/dataLayer/harperBridge/ResourceBridge.d.ts +2 -2
  411. package/dist/dataLayer/harperBridge/ResourceBridge.js +26 -25
  412. package/dist/dataLayer/harperBridge/ResourceBridge.js.map +1 -1
  413. package/dist/dataLayer/harperBridge/TableSizeObject.d.ts +1 -0
  414. package/dist/dataLayer/harperBridge/TableSizeObject.js.map +1 -1
  415. package/dist/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.d.ts +4 -4
  416. package/dist/dataLayer/harperBridge/bridgeUtility/insertUpdateValidate.js +4 -4
  417. package/dist/dataLayer/harperBridge/harperBridge.d.ts +2 -3
  418. package/dist/dataLayer/harperBridge/harperBridge.js +38 -4
  419. package/dist/dataLayer/harperBridge/harperBridge.js.map +1 -1
  420. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.d.ts +1 -2
  421. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js +7 -6
  422. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateAttribute.js.map +1 -1
  423. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.d.ts +1 -2
  424. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js +4 -4
  425. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateRecords.js.map +1 -1
  426. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js +1 -1
  427. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateSchema.js.map +1 -1
  428. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js +5 -4
  429. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbCreateTable.js.map +1 -1
  430. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.d.ts +1 -2
  431. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js +4 -4
  432. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteAuditLogsBefore.js.map +1 -1
  433. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDeleteRecords.js +4 -4
  434. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.d.ts +1 -2
  435. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js +5 -5
  436. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropAttribute.js.map +1 -1
  437. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js +4 -4
  438. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropSchema.js.map +1 -1
  439. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js +5 -5
  440. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbDropTable.js.map +1 -1
  441. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbFlush.js +1 -1
  442. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetBackup.js +3 -3
  443. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByHash.js +1 -1
  444. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js +2 -2
  445. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbGetDataByValue.js.map +1 -1
  446. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbReadAuditLog.js +5 -5
  447. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.d.ts +1 -2
  448. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js +8 -8
  449. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByConditions.js.map +1 -1
  450. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.d.ts +1 -1
  451. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByHash.js +1 -1
  452. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.d.ts +1 -2
  453. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js +3 -3
  454. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbSearchByValue.js.map +1 -1
  455. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpdateRecords.js +3 -3
  456. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.d.ts +1 -2
  457. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js +5 -5
  458. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbMethods/lmdbUpsertRecords.js.map +1 -1
  459. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.d.ts +1 -2
  460. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js +1 -1
  461. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/LMDBCreateAttributeObject.js.map +1 -1
  462. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js +2 -2
  463. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializeHashSearch.js.map +1 -1
  464. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/initializePaths.js +2 -2
  465. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js +4 -4
  466. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCheckForNewAttributes.js.map +1 -1
  467. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.d.ts +1 -2
  468. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js +5 -3
  469. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbCreateTransactionsAuditEnvironment.js.map +1 -1
  470. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbGetTableSize.js +2 -2
  471. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.d.ts +1 -2
  472. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js +4 -4
  473. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbProcessRows.js.map +1 -1
  474. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbSearch.js +5 -5
  475. package/dist/dataLayer/harperBridge/lmdbBridge/lmdbUtility/lmdbWriteTransaction.js +4 -4
  476. package/dist/dataLayer/hdbInfoController.d.ts +4 -8
  477. package/dist/dataLayer/hdbInfoController.js +66 -31
  478. package/dist/dataLayer/hdbInfoController.js.map +1 -1
  479. package/dist/dataLayer/insert.d.ts +14 -26
  480. package/dist/dataLayer/insert.js +63 -28
  481. package/dist/dataLayer/insert.js.map +1 -1
  482. package/dist/dataLayer/readAuditLog.d.ts +1 -3
  483. package/dist/dataLayer/readAuditLog.js +45 -13
  484. package/dist/dataLayer/readAuditLog.js.map +1 -1
  485. package/dist/dataLayer/schema.d.ts +10 -10
  486. package/dist/dataLayer/schema.js +124 -89
  487. package/dist/dataLayer/schema.js.map +1 -1
  488. package/dist/dataLayer/schemaDescribe.d.ts +4 -4
  489. package/dist/dataLayer/schemaDescribe.js +78 -41
  490. package/dist/dataLayer/schemaDescribe.js.map +1 -1
  491. package/dist/dataLayer/search.d.ts +4 -4
  492. package/dist/dataLayer/search.js +12 -13
  493. package/dist/dataLayer/search.js.map +1 -1
  494. package/dist/dataLayer/transaction.d.ts +1 -1
  495. package/dist/dataLayer/transaction.js +3 -4
  496. package/dist/dataLayer/transaction.js.map +1 -1
  497. package/dist/dataLayer/update.d.ts +2 -8
  498. package/dist/dataLayer/update.js +53 -18
  499. package/dist/dataLayer/update.js.map +1 -1
  500. package/dist/globals.d.ts +1 -1
  501. package/dist/globals.js +1 -0
  502. package/dist/globals.js.map +1 -1
  503. package/dist/index.d.ts +4 -0
  504. package/dist/index.js +4 -1
  505. package/dist/index.js.map +1 -1
  506. package/dist/json/systemSchema.json +65 -0
  507. package/dist/launchServiceScripts/launchHarperDB.d.ts +1 -0
  508. package/dist/launchServiceScripts/launchHarperDB.js +3 -0
  509. package/dist/launchServiceScripts/launchHarperDB.js.map +1 -0
  510. package/dist/launchServiceScripts/utility/checkNodeVersion.js +3 -0
  511. package/dist/launchServiceScripts/utility/checkNodeVersion.js.map +1 -1
  512. package/dist/resources/DatabaseTransaction.d.ts +14 -6
  513. package/dist/resources/DatabaseTransaction.js +39 -15
  514. package/dist/resources/DatabaseTransaction.js.map +1 -1
  515. package/dist/resources/ErrorResource.d.ts +1 -1
  516. package/dist/resources/ErrorResource.js +3 -1
  517. package/dist/resources/ErrorResource.js.map +1 -1
  518. package/dist/resources/LMDBTransaction.d.ts +10 -13
  519. package/dist/resources/LMDBTransaction.js +18 -7
  520. package/dist/resources/LMDBTransaction.js.map +1 -1
  521. package/dist/resources/RecordEncoder.d.ts +10 -12
  522. package/dist/resources/RecordEncoder.js +38 -38
  523. package/dist/resources/RecordEncoder.js.map +1 -1
  524. package/dist/resources/RequestTarget.d.ts +1 -0
  525. package/dist/resources/RequestTarget.js.map +1 -1
  526. package/dist/resources/Resource.d.ts +25 -5
  527. package/dist/resources/Resource.js +43 -10
  528. package/dist/resources/Resource.js.map +1 -1
  529. package/dist/resources/ResourceInterface.d.ts +24 -5
  530. package/dist/resources/ResourceInterface.js +20 -0
  531. package/dist/resources/ResourceInterface.js.map +1 -1
  532. package/dist/resources/Resources.d.ts +3 -4
  533. package/dist/resources/Resources.js +7 -6
  534. package/dist/resources/Resources.js.map +1 -1
  535. package/dist/resources/RocksIndexStore.js +3 -0
  536. package/dist/resources/RocksIndexStore.js.map +1 -1
  537. package/dist/resources/RocksTransactionLogStore.d.ts +1 -1
  538. package/dist/resources/RocksTransactionLogStore.js +10 -3
  539. package/dist/resources/RocksTransactionLogStore.js.map +1 -1
  540. package/dist/resources/Table.d.ts +76 -329
  541. package/dist/resources/Table.js +306 -116
  542. package/dist/resources/Table.js.map +1 -1
  543. package/dist/resources/analytics/metadata.d.ts +1 -0
  544. package/dist/resources/analytics/metadata.js +1 -0
  545. package/dist/resources/analytics/metadata.js.map +1 -1
  546. package/dist/resources/analytics/read.d.ts +8 -1
  547. package/dist/resources/analytics/read.js +69 -8
  548. package/dist/resources/analytics/read.js.map +1 -1
  549. package/dist/resources/analytics/write.d.ts +28 -0
  550. package/dist/resources/analytics/write.js +232 -20
  551. package/dist/resources/analytics/write.js.map +1 -1
  552. package/dist/resources/auditStore.d.ts +18 -13
  553. package/dist/resources/auditStore.js +16 -8
  554. package/dist/resources/auditStore.js.map +1 -1
  555. package/dist/resources/blob.d.ts +16 -27
  556. package/dist/resources/blob.js +8 -8
  557. package/dist/resources/blob.js.map +1 -1
  558. package/dist/resources/dataLoader.d.ts +1 -1
  559. package/dist/resources/dataLoader.js +13 -13
  560. package/dist/resources/databases.d.ts +17 -0
  561. package/dist/resources/databases.js +175 -59
  562. package/dist/resources/databases.js.map +1 -1
  563. package/dist/resources/graphql.d.ts +1 -7
  564. package/dist/resources/graphql.js +267 -173
  565. package/dist/resources/graphql.js.map +1 -1
  566. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.d.ts +17 -1
  567. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js +327 -59
  568. package/dist/resources/indexes/HierarchicalNavigableSmallWorld.js.map +1 -1
  569. package/dist/resources/indexes/vector.d.ts +1 -0
  570. package/dist/resources/indexes/vector.js +14 -0
  571. package/dist/resources/indexes/vector.js.map +1 -1
  572. package/dist/resources/jsonSchemaTypes.d.ts +60 -0
  573. package/dist/resources/jsonSchemaTypes.js +78 -0
  574. package/dist/resources/jsonSchemaTypes.js.map +1 -0
  575. package/dist/resources/loadEnv.d.ts +2 -5
  576. package/dist/resources/loadEnv.js +21 -18
  577. package/dist/resources/loadEnv.js.map +1 -1
  578. package/dist/resources/login.d.ts +2 -3
  579. package/dist/resources/login.js +5 -4
  580. package/dist/resources/login.js.map +1 -1
  581. package/dist/resources/models/Models.d.ts +45 -0
  582. package/dist/resources/models/Models.js +265 -0
  583. package/dist/resources/models/Models.js.map +1 -0
  584. package/dist/resources/models/TestBackend.d.ts +15 -0
  585. package/dist/resources/models/TestBackend.js +71 -0
  586. package/dist/resources/models/TestBackend.js.map +1 -0
  587. package/dist/resources/models/agentLoop.d.ts +125 -0
  588. package/dist/resources/models/agentLoop.js +746 -0
  589. package/dist/resources/models/agentLoop.js.map +1 -0
  590. package/dist/resources/models/analyticsTable.d.ts +65 -0
  591. package/dist/resources/models/analyticsTable.js +166 -0
  592. package/dist/resources/models/analyticsTable.js.map +1 -0
  593. package/dist/resources/models/backendHelpers.d.ts +57 -0
  594. package/dist/resources/models/backendHelpers.js +109 -0
  595. package/dist/resources/models/backendHelpers.js.map +1 -0
  596. package/dist/resources/models/backendRegistry.d.ts +36 -0
  597. package/dist/resources/models/backendRegistry.js +54 -0
  598. package/dist/resources/models/backendRegistry.js.map +1 -0
  599. package/dist/resources/models/bootstrap.d.ts +24 -0
  600. package/dist/resources/models/bootstrap.js +112 -0
  601. package/dist/resources/models/bootstrap.js.map +1 -0
  602. package/dist/resources/models/embedHook.d.ts +33 -0
  603. package/dist/resources/models/embedHook.js +127 -0
  604. package/dist/resources/models/embedHook.js.map +1 -0
  605. package/dist/resources/models/types.d.ts +301 -0
  606. package/dist/resources/models/types.js +11 -0
  607. package/dist/resources/models/types.js.map +1 -0
  608. package/dist/resources/openApi.js +74 -34
  609. package/dist/resources/openApi.js.map +1 -1
  610. package/dist/resources/replayLogs.js +7 -1
  611. package/dist/resources/replayLogs.js.map +1 -1
  612. package/dist/resources/replayLogsGuards.d.ts +9 -0
  613. package/dist/resources/replayLogsGuards.js +47 -0
  614. package/dist/resources/replayLogsGuards.js.map +1 -1
  615. package/dist/resources/roles.d.ts +1 -7
  616. package/dist/resources/roles.js +67 -71
  617. package/dist/resources/roles.js.map +1 -1
  618. package/dist/resources/search.d.ts +18 -1
  619. package/dist/resources/search.js +349 -140
  620. package/dist/resources/search.js.map +1 -1
  621. package/dist/resources/tracked.d.ts +1 -1
  622. package/dist/resources/tracked.js +23 -15
  623. package/dist/resources/tracked.js.map +1 -1
  624. package/dist/resources/transaction.d.ts +1 -1
  625. package/dist/resources/transaction.js +1 -1
  626. package/dist/resources/transaction.js.map +1 -1
  627. package/dist/resources/transactionBroadcast.d.ts +1 -1
  628. package/dist/resources/transactionBroadcast.js.map +1 -1
  629. package/dist/security/auth.d.ts +1 -5
  630. package/dist/security/auth.js +34 -25
  631. package/dist/security/auth.js.map +1 -1
  632. package/dist/security/certificateVerification/crlVerification.js +7 -1
  633. package/dist/security/certificateVerification/crlVerification.js.map +1 -1
  634. package/dist/security/cryptoHash.d.ts +2 -2
  635. package/dist/security/cryptoHash.js +37 -5
  636. package/dist/security/cryptoHash.js.map +1 -1
  637. package/dist/security/data_objects/PermissionAttributeResponseObject.d.ts +3 -4
  638. package/dist/security/data_objects/PermissionAttributeResponseObject.js +4 -1
  639. package/dist/security/data_objects/PermissionAttributeResponseObject.js.map +1 -1
  640. package/dist/security/data_objects/PermissionResponseObject.d.ts +9 -9
  641. package/dist/security/data_objects/PermissionResponseObject.js +15 -8
  642. package/dist/security/data_objects/PermissionResponseObject.js.map +1 -1
  643. package/dist/security/data_objects/PermissionTableResponseObject.d.ts +5 -6
  644. package/dist/security/data_objects/PermissionTableResponseObject.js +6 -1
  645. package/dist/security/data_objects/PermissionTableResponseObject.js.map +1 -1
  646. package/dist/security/fastifyAuth.d.ts +2 -2
  647. package/dist/security/fastifyAuth.js +131 -22
  648. package/dist/security/fastifyAuth.js.map +1 -1
  649. package/dist/security/impersonation.js +15 -15
  650. package/dist/security/jsLoader.js +18 -5
  651. package/dist/security/jsLoader.js.map +1 -1
  652. package/dist/security/keys.d.ts +45 -48
  653. package/dist/security/keys.js +160 -114
  654. package/dist/security/keys.js.map +1 -1
  655. package/dist/security/permissionsTranslator.js +2 -2
  656. package/dist/security/role.d.ts +5 -5
  657. package/dist/security/role.js +70 -35
  658. package/dist/security/role.js.map +1 -1
  659. package/dist/security/tokenAuthentication.d.ts +13 -0
  660. package/dist/security/tokenAuthentication.js +57 -27
  661. package/dist/security/tokenAuthentication.js.map +1 -1
  662. package/dist/security/user.js +74 -38
  663. package/dist/security/user.js.map +1 -1
  664. package/dist/server/DurableSubscriptionsSession.d.ts +4 -2
  665. package/dist/server/DurableSubscriptionsSession.js +71 -55
  666. package/dist/server/DurableSubscriptionsSession.js.map +1 -1
  667. package/dist/server/REST.d.ts +1 -8
  668. package/dist/server/REST.js +17 -16
  669. package/dist/server/REST.js.map +1 -1
  670. package/dist/server/Server.d.ts +23 -4
  671. package/dist/server/Server.js +1 -1
  672. package/dist/server/Server.js.map +1 -1
  673. package/dist/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
  674. package/dist/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
  675. package/dist/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
  676. package/dist/server/fastifyRoutes.d.ts +1 -4
  677. package/dist/server/fastifyRoutes.js +34 -30
  678. package/dist/server/fastifyRoutes.js.map +1 -1
  679. package/dist/server/graphqlQuerying.d.ts +1 -1
  680. package/dist/server/graphqlQuerying.js +8 -7
  681. package/dist/server/graphqlQuerying.js.map +1 -1
  682. package/dist/server/http.d.ts +9 -4
  683. package/dist/server/http.js +523 -47
  684. package/dist/server/http.js.map +1 -1
  685. package/dist/server/itc/serverHandlers.js +66 -15
  686. package/dist/server/itc/serverHandlers.js.map +1 -1
  687. package/dist/server/jobs/JobObject.d.ts +3 -3
  688. package/dist/server/jobs/JobObject.js +53 -7
  689. package/dist/server/jobs/JobObject.js.map +1 -1
  690. package/dist/server/jobs/jobProcess.js +64 -24
  691. package/dist/server/jobs/jobProcess.js.map +1 -1
  692. package/dist/server/jobs/jobRunner.d.ts +7 -6
  693. package/dist/server/jobs/jobRunner.js +68 -30
  694. package/dist/server/jobs/jobRunner.js.map +1 -1
  695. package/dist/server/jobs/jobs.d.ts +18 -7
  696. package/dist/server/jobs/jobs.js +93 -61
  697. package/dist/server/jobs/jobs.js.map +1 -1
  698. package/dist/server/loadRootComponents.js +1 -1
  699. package/dist/server/middlewareChain.d.ts +80 -0
  700. package/dist/server/middlewareChain.js +252 -0
  701. package/dist/server/middlewareChain.js.map +1 -0
  702. package/dist/server/mqtt.d.ts +1 -8
  703. package/dist/server/mqtt.js +22 -17
  704. package/dist/server/mqtt.js.map +1 -1
  705. package/dist/server/nodeName.js +46 -13
  706. package/dist/server/nodeName.js.map +1 -1
  707. package/dist/server/operationsServer.d.ts +2 -2
  708. package/dist/server/operationsServer.js +106 -33
  709. package/dist/server/operationsServer.js.map +1 -1
  710. package/dist/server/serverHelpers/Headers.d.ts +4 -4
  711. package/dist/server/serverHelpers/Headers.js +2 -0
  712. package/dist/server/serverHelpers/Headers.js.map +1 -1
  713. package/dist/server/serverHelpers/JSONStream.d.ts +7 -1
  714. package/dist/server/serverHelpers/JSONStream.js +12 -3
  715. package/dist/server/serverHelpers/JSONStream.js.map +1 -1
  716. package/dist/server/serverHelpers/Request.d.ts +106 -8
  717. package/dist/server/serverHelpers/Request.js +370 -9
  718. package/dist/server/serverHelpers/Request.js.map +1 -1
  719. package/dist/server/serverHelpers/contentTypes.d.ts +1 -1
  720. package/dist/server/serverHelpers/contentTypes.js +36 -7
  721. package/dist/server/serverHelpers/contentTypes.js.map +1 -1
  722. package/dist/server/serverHelpers/multipartParser.d.ts +21 -0
  723. package/dist/server/serverHelpers/multipartParser.js +142 -0
  724. package/dist/server/serverHelpers/multipartParser.js.map +1 -0
  725. package/dist/server/serverHelpers/progressEmitter.d.ts +25 -0
  726. package/dist/server/serverHelpers/progressEmitter.js +103 -0
  727. package/dist/server/serverHelpers/progressEmitter.js.map +1 -0
  728. package/dist/server/serverHelpers/serverHandlers.d.ts +1 -1
  729. package/dist/server/serverHelpers/serverHandlers.js +38 -7
  730. package/dist/server/serverHelpers/serverHandlers.js.map +1 -1
  731. package/dist/server/serverHelpers/serverUtilities.d.ts +4 -2
  732. package/dist/server/serverHelpers/serverUtilities.js +97 -93
  733. package/dist/server/serverHelpers/serverUtilities.js.map +1 -1
  734. package/dist/server/static.js +8 -5
  735. package/dist/server/static.js.map +1 -1
  736. package/dist/server/status/index.js +3 -3
  737. package/dist/server/storageReclamation.d.ts +10 -0
  738. package/dist/server/storageReclamation.js +68 -9
  739. package/dist/server/storageReclamation.js.map +1 -1
  740. package/dist/server/threads/itc.js +7 -4
  741. package/dist/server/threads/itc.js.map +1 -1
  742. package/dist/server/threads/manageThreads.d.ts +1 -1
  743. package/dist/server/threads/manageThreads.js +110 -26
  744. package/dist/server/threads/manageThreads.js.map +1 -1
  745. package/dist/server/threads/socketRouter.d.ts +0 -1
  746. package/dist/server/threads/socketRouter.js +8 -271
  747. package/dist/server/threads/socketRouter.js.map +1 -1
  748. package/dist/server/threads/threadServer.d.ts +1 -0
  749. package/dist/server/threads/threadServer.js +360 -118
  750. package/dist/server/threads/threadServer.js.map +1 -1
  751. package/dist/server/threads/workerProcessGuard.d.ts +42 -0
  752. package/dist/server/threads/workerProcessGuard.js +114 -0
  753. package/dist/server/threads/workerProcessGuard.js.map +1 -0
  754. package/dist/server/throttle.js +17 -0
  755. package/dist/server/throttle.js.map +1 -1
  756. package/dist/sqlTranslator/SelectValidator.d.ts +21 -24
  757. package/dist/sqlTranslator/SelectValidator.js +86 -47
  758. package/dist/sqlTranslator/SelectValidator.js.map +1 -1
  759. package/dist/sqlTranslator/alasqlFunctionImporter.d.ts +6 -2
  760. package/dist/sqlTranslator/alasqlFunctionImporter.js +40 -3
  761. package/dist/sqlTranslator/alasqlFunctionImporter.js.map +1 -1
  762. package/dist/sqlTranslator/deleteTranslator.d.ts +4 -7
  763. package/dist/sqlTranslator/deleteTranslator.js +48 -14
  764. package/dist/sqlTranslator/deleteTranslator.js.map +1 -1
  765. package/dist/sqlTranslator/index.d.ts +10 -9
  766. package/dist/sqlTranslator/index.js +69 -30
  767. package/dist/sqlTranslator/index.js.map +1 -1
  768. package/dist/sqlTranslator/sql_statement_bucket.d.ts +10 -10
  769. package/dist/sqlTranslator/sql_statement_bucket.js +55 -13
  770. package/dist/sqlTranslator/sql_statement_bucket.js.map +1 -1
  771. package/dist/upgrade/UpgradeObjects.d.ts +2 -3
  772. package/dist/upgrade/UpgradeObjects.js +37 -4
  773. package/dist/upgrade/UpgradeObjects.js.map +1 -1
  774. package/dist/upgrade/directives/5-1-0.d.ts +6 -0
  775. package/dist/upgrade/directives/5-1-0.js +114 -0
  776. package/dist/upgrade/directives/5-1-0.js.map +1 -0
  777. package/dist/upgrade/directives/directivesController.d.ts +10 -10
  778. package/dist/upgrade/directives/directivesController.js +52 -11
  779. package/dist/upgrade/directives/directivesController.js.map +1 -1
  780. package/dist/upgrade/directivesManager.d.ts +1 -1
  781. package/dist/upgrade/directivesManager.js +53 -18
  782. package/dist/upgrade/directivesManager.js.map +1 -1
  783. package/dist/upgrade/upgradePrompt.d.ts +2 -8
  784. package/dist/upgrade/upgradePrompt.js +55 -60
  785. package/dist/upgrade/upgradePrompt.js.map +1 -1
  786. package/dist/upgrade/upgradeUtilities.d.ts +1 -1
  787. package/dist/upgrade/upgradeUtilities.js +37 -5
  788. package/dist/upgrade/upgradeUtilities.js.map +1 -1
  789. package/dist/utility/OperationFunctionCaller.d.ts +1 -1
  790. package/dist/utility/OperationFunctionCaller.js +45 -10
  791. package/dist/utility/OperationFunctionCaller.js.map +1 -1
  792. package/dist/utility/assignCmdEnvVariables.d.ts +1 -2
  793. package/dist/utility/assignCmdEnvVariables.js +8 -4
  794. package/dist/utility/assignCmdEnvVariables.js.map +1 -1
  795. package/dist/utility/common_utils.d.ts +80 -77
  796. package/dist/utility/common_utils.js +140 -79
  797. package/dist/utility/common_utils.js.map +1 -1
  798. package/dist/utility/environment/environmentManager.d.ts +12 -11
  799. package/dist/utility/environment/environmentManager.js +75 -29
  800. package/dist/utility/environment/environmentManager.js.map +1 -1
  801. package/dist/utility/environment/systemInformation.d.ts +4 -0
  802. package/dist/utility/environment/systemInformation.js +27 -16
  803. package/dist/utility/environment/systemInformation.js.map +1 -1
  804. package/dist/utility/errors/commonErrors.d.ts +192 -168
  805. package/dist/utility/errors/commonErrors.js +49 -18
  806. package/dist/utility/errors/commonErrors.js.map +1 -1
  807. package/dist/utility/errors/hdbError.d.ts +37 -51
  808. package/dist/utility/errors/hdbError.js +65 -26
  809. package/dist/utility/errors/hdbError.js.map +1 -1
  810. package/dist/utility/expandEnvVar.d.ts +61 -0
  811. package/dist/utility/expandEnvVar.js +113 -0
  812. package/dist/utility/expandEnvVar.js.map +1 -0
  813. package/dist/utility/functions/geo.js +2 -2
  814. package/dist/utility/functions/sql/alaSQLExtension.js +1 -1
  815. package/dist/utility/globalSchema.d.ts +13 -4
  816. package/dist/utility/globalSchema.js +14 -11
  817. package/dist/utility/globalSchema.js.map +1 -1
  818. package/dist/utility/hdbTerms.d.ts +54 -1
  819. package/dist/utility/hdbTerms.js +54 -1
  820. package/dist/utility/hdbTerms.js.map +1 -1
  821. package/dist/utility/install/checkJWTTokensExist.js +1 -1
  822. package/dist/utility/install/installer.d.ts +9 -12
  823. package/dist/utility/install/installer.js +117 -54
  824. package/dist/utility/install/installer.js.map +1 -1
  825. package/dist/utility/installation.js +3 -3
  826. package/dist/utility/lmdb/DBIDefinition.d.ts +4 -4
  827. package/dist/utility/lmdb/DBIDefinition.js +5 -1
  828. package/dist/utility/lmdb/DBIDefinition.js.map +1 -1
  829. package/dist/utility/lmdb/DeleteRecordsResponseObject.d.ts +3 -6
  830. package/dist/utility/lmdb/DeleteRecordsResponseObject.js +2 -1
  831. package/dist/utility/lmdb/DeleteRecordsResponseObject.js.map +1 -1
  832. package/dist/utility/lmdb/InsertRecordsResponseObject.d.ts +3 -5
  833. package/dist/utility/lmdb/InsertRecordsResponseObject.js +2 -1
  834. package/dist/utility/lmdb/InsertRecordsResponseObject.js.map +1 -1
  835. package/dist/utility/lmdb/OpenDBIObject.d.ts +12 -15
  836. package/dist/utility/lmdb/OpenDBIObject.js +68 -6
  837. package/dist/utility/lmdb/OpenDBIObject.js.map +1 -1
  838. package/dist/utility/lmdb/OpenEnvironmentObject.d.ts +5 -8
  839. package/dist/utility/lmdb/OpenEnvironmentObject.js +52 -4
  840. package/dist/utility/lmdb/OpenEnvironmentObject.js.map +1 -1
  841. package/dist/utility/lmdb/UpdateRecordsResponseObject.d.ts +3 -6
  842. package/dist/utility/lmdb/UpdateRecordsResponseObject.js +2 -1
  843. package/dist/utility/lmdb/UpdateRecordsResponseObject.js.map +1 -1
  844. package/dist/utility/lmdb/UpsertRecordsResponseObject.d.ts +3 -5
  845. package/dist/utility/lmdb/UpsertRecordsResponseObject.js +2 -1
  846. package/dist/utility/lmdb/UpsertRecordsResponseObject.js.map +1 -1
  847. package/dist/utility/lmdb/cleanLMDBMap.d.ts +1 -1
  848. package/dist/utility/lmdb/cleanLMDBMap.js +44 -7
  849. package/dist/utility/lmdb/cleanLMDBMap.js.map +1 -1
  850. package/dist/utility/lmdb/commonUtility.d.ts +8 -9
  851. package/dist/utility/lmdb/commonUtility.js +46 -17
  852. package/dist/utility/lmdb/commonUtility.js.map +1 -1
  853. package/dist/utility/lmdb/deleteUtility.d.ts +2 -3
  854. package/dist/utility/lmdb/deleteUtility.js +51 -16
  855. package/dist/utility/lmdb/deleteUtility.js.map +1 -1
  856. package/dist/utility/lmdb/environmentUtility.d.ts +69 -36
  857. package/dist/utility/lmdb/environmentUtility.js +91 -51
  858. package/dist/utility/lmdb/environmentUtility.js.map +1 -1
  859. package/dist/utility/lmdb/searchCursorFunctions.d.ts +19 -19
  860. package/dist/utility/lmdb/searchCursorFunctions.js +46 -14
  861. package/dist/utility/lmdb/searchCursorFunctions.js.map +1 -1
  862. package/dist/utility/lmdb/searchUtility.d.ts +142 -73
  863. package/dist/utility/lmdb/searchUtility.js +91 -55
  864. package/dist/utility/lmdb/searchUtility.js.map +1 -1
  865. package/dist/utility/lmdb/terms.d.ts +34 -34
  866. package/dist/utility/lmdb/terms.js +12 -22
  867. package/dist/utility/lmdb/terms.js.map +1 -1
  868. package/dist/utility/lmdb/writeUtility.d.ts +3 -6
  869. package/dist/utility/lmdb/writeUtility.js +61 -28
  870. package/dist/utility/lmdb/writeUtility.js.map +1 -1
  871. package/dist/utility/logging/harper_logger.d.ts +87 -103
  872. package/dist/utility/logging/harper_logger.js +177 -82
  873. package/dist/utility/logging/harper_logger.js.map +1 -1
  874. package/dist/utility/logging/logRotator.d.ts +2 -10
  875. package/dist/utility/logging/logRotator.js +67 -32
  876. package/dist/utility/logging/logRotator.js.map +1 -1
  877. package/dist/utility/logging/logger.js +4 -4
  878. package/dist/utility/logging/readLog.d.ts +1 -1
  879. package/dist/utility/logging/readLog.js +54 -17
  880. package/dist/utility/logging/readLog.js.map +1 -1
  881. package/dist/utility/logging/transactionLog.d.ts +2 -2
  882. package/dist/utility/logging/transactionLog.js +51 -16
  883. package/dist/utility/logging/transactionLog.js.map +1 -1
  884. package/dist/utility/mount_hdb.d.ts +1 -2
  885. package/dist/utility/mount_hdb.js +54 -17
  886. package/dist/utility/mount_hdb.js.map +1 -1
  887. package/dist/utility/npmUtilities.d.ts +1 -1
  888. package/dist/utility/npmUtilities.js +54 -19
  889. package/dist/utility/npmUtilities.js.map +1 -1
  890. package/dist/utility/operation_authorization.d.ts +36 -9
  891. package/dist/utility/operation_authorization.js +135 -86
  892. package/dist/utility/operation_authorization.js.map +1 -1
  893. package/dist/utility/packageUtils.d.ts +0 -2
  894. package/dist/utility/packageUtils.js +7 -17
  895. package/dist/utility/packageUtils.js.map +1 -1
  896. package/dist/utility/password.js +2 -2
  897. package/dist/utility/processManagement/processManagement.js +2 -2
  898. package/dist/utility/processManagement/servicesConfig.js +1 -1
  899. package/dist/utility/signalling.d.ts +2 -2
  900. package/dist/utility/signalling.js +51 -16
  901. package/dist/utility/signalling.js.map +1 -1
  902. package/dist/utility/watcherFallback.d.ts +36 -0
  903. package/dist/utility/watcherFallback.js +73 -0
  904. package/dist/utility/watcherFallback.js.map +1 -0
  905. package/dist/validation/analyticsValidator.d.ts +1 -0
  906. package/dist/validation/analyticsValidator.js +80 -0
  907. package/dist/validation/analyticsValidator.js.map +1 -0
  908. package/dist/validation/bulkDeleteValidator.d.ts +1 -2
  909. package/dist/validation/bulkDeleteValidator.js +49 -11
  910. package/dist/validation/bulkDeleteValidator.js.map +1 -1
  911. package/dist/validation/check_permissions.d.ts +1 -2
  912. package/dist/validation/check_permissions.js +38 -3
  913. package/dist/validation/check_permissions.js.map +1 -1
  914. package/dist/validation/common_validators.d.ts +20 -20
  915. package/dist/validation/common_validators.js +62 -31
  916. package/dist/validation/common_validators.js.map +1 -1
  917. package/dist/validation/configValidator.d.ts +4 -4
  918. package/dist/validation/configValidator.js +189 -54
  919. package/dist/validation/configValidator.js.map +1 -1
  920. package/dist/validation/deleteValidator.d.ts +1 -2
  921. package/dist/validation/deleteValidator.js +49 -11
  922. package/dist/validation/deleteValidator.js.map +1 -1
  923. package/dist/validation/fileLoadValidator.d.ts +4 -4
  924. package/dist/validation/fileLoadValidator.js +67 -32
  925. package/dist/validation/fileLoadValidator.js.map +1 -1
  926. package/dist/validation/insertValidator.d.ts +1 -2
  927. package/dist/validation/insertValidator.js +48 -10
  928. package/dist/validation/insertValidator.js.map +1 -1
  929. package/dist/validation/installValidator.d.ts +2 -2
  930. package/dist/validation/installValidator.js +47 -10
  931. package/dist/validation/installValidator.js.map +1 -1
  932. package/dist/validation/readLogValidator.d.ts +1 -2
  933. package/dist/validation/readLogValidator.js +60 -22
  934. package/dist/validation/readLogValidator.js.map +1 -1
  935. package/dist/validation/role_validation.d.ts +3 -3
  936. package/dist/validation/role_validation.js +55 -19
  937. package/dist/validation/role_validation.js.map +1 -1
  938. package/dist/validation/schemaMetadataValidator.d.ts +3 -4
  939. package/dist/validation/schemaMetadataValidator.js +11 -12
  940. package/dist/validation/schemaMetadataValidator.js.map +1 -1
  941. package/dist/validation/searchValidator.d.ts +1 -2
  942. package/dist/validation/searchValidator.js +82 -43
  943. package/dist/validation/searchValidator.js.map +1 -1
  944. package/dist/validation/statusValidator.d.ts +1 -1
  945. package/dist/validation/transactionLogValidator.d.ts +3 -3
  946. package/dist/validation/transactionLogValidator.js +52 -17
  947. package/dist/validation/transactionLogValidator.js.map +1 -1
  948. package/dist/validation/user_validation.d.ts +3 -3
  949. package/dist/validation/user_validation.js +38 -6
  950. package/dist/validation/user_validation.js.map +1 -1
  951. package/dist/validation/validationWrapper.d.ts +3 -3
  952. package/dist/validation/validationWrapper.js +4 -5
  953. package/dist/validation/validationWrapper.js.map +1 -1
  954. package/index.ts +5 -0
  955. package/json/systemSchema.json +65 -0
  956. package/launchServiceScripts/utility/checkNodeVersion.js +2 -0
  957. package/package.json +38 -24
  958. package/resources/DESIGN.md +98 -0
  959. package/resources/DatabaseTransaction.ts +58 -30
  960. package/resources/ErrorResource.ts +2 -1
  961. package/resources/LMDBTransaction.ts +38 -29
  962. package/resources/RecordEncoder.ts +41 -39
  963. package/resources/RequestTarget.ts +2 -0
  964. package/resources/Resource.ts +96 -56
  965. package/resources/ResourceInterface.ts +44 -21
  966. package/resources/Resources.ts +8 -8
  967. package/resources/RocksIndexStore.ts +3 -0
  968. package/resources/RocksTransactionLogStore.ts +13 -4
  969. package/resources/Table.ts +440 -223
  970. package/resources/analytics/metadata.ts +1 -0
  971. package/resources/analytics/read.ts +99 -10
  972. package/resources/analytics/write.ts +240 -17
  973. package/resources/auditStore.ts +30 -19
  974. package/resources/blob.ts +53 -53
  975. package/resources/dataLoader.ts +4 -4
  976. package/resources/databases.ts +208 -74
  977. package/resources/graphql.ts +267 -165
  978. package/resources/indexes/HierarchicalNavigableSmallWorld.ts +310 -65
  979. package/resources/indexes/vector.ts +17 -0
  980. package/resources/jsonSchemaTypes.ts +102 -0
  981. package/resources/loadEnv.ts +21 -17
  982. package/resources/login.ts +5 -3
  983. package/resources/models/Models.ts +304 -0
  984. package/resources/models/TestBackend.ts +83 -0
  985. package/resources/models/agentLoop.ts +895 -0
  986. package/resources/models/analyticsTable.ts +199 -0
  987. package/resources/models/backendHelpers.ts +116 -0
  988. package/resources/models/backendRegistry.ts +66 -0
  989. package/resources/models/bootstrap.ts +135 -0
  990. package/resources/models/embedHook.ts +138 -0
  991. package/resources/models/types.ts +296 -0
  992. package/resources/openApi.ts +65 -31
  993. package/resources/replayLogs.ts +20 -9
  994. package/resources/replayLogsGuards.ts +45 -0
  995. package/resources/roles.ts +62 -67
  996. package/resources/search.ts +355 -135
  997. package/resources/tracked.ts +18 -9
  998. package/resources/transaction.ts +8 -8
  999. package/resources/transactionBroadcast.ts +3 -3
  1000. package/schema.graphql +7 -0
  1001. package/security/auth.ts +35 -26
  1002. package/security/certificateVerification/crlVerification.ts +11 -4
  1003. package/security/{cryptoHash.js → cryptoHash.ts} +3 -8
  1004. package/security/data_objects/{PermissionAttributeResponseObject.js → PermissionAttributeResponseObject.ts} +4 -4
  1005. package/security/data_objects/{PermissionResponseObject.js → PermissionResponseObject.ts} +12 -11
  1006. package/security/data_objects/{PermissionTableResponseObject.js → PermissionTableResponseObject.ts} +6 -4
  1007. package/security/{fastifyAuth.js → fastifyAuth.ts} +93 -20
  1008. package/security/impersonation.ts +3 -3
  1009. package/security/jsLoader.ts +22 -8
  1010. package/security/{keys.js → keys.ts} +113 -121
  1011. package/security/permissionsTranslator.js +2 -2
  1012. package/security/{role.js → role.ts} +26 -33
  1013. package/security/tokenAuthentication.ts +34 -7
  1014. package/security/user.ts +26 -22
  1015. package/server/DESIGN.md +139 -0
  1016. package/server/DurableSubscriptionsSession.ts +67 -50
  1017. package/server/REST.ts +120 -107
  1018. package/server/Server.ts +31 -12
  1019. package/server/fastifyRoutes/helpers/getCORSOptions.js +1 -1
  1020. package/server/fastifyRoutes/helpers/getHeaderTimeoutConfig.js +1 -1
  1021. package/server/fastifyRoutes/helpers/getServerOptions.js +1 -1
  1022. package/server/fastifyRoutes.ts +37 -33
  1023. package/server/graphqlQuerying.ts +6 -5
  1024. package/server/http.ts +517 -26
  1025. package/server/itc/serverHandlers.js +75 -14
  1026. package/server/jobs/{JobObject.js → JobObject.ts} +13 -6
  1027. package/server/jobs/{jobProcess.js → jobProcess.ts} +20 -16
  1028. package/server/jobs/{jobRunner.js → jobRunner.ts} +20 -21
  1029. package/server/jobs/{jobs.js → jobs.ts} +41 -44
  1030. package/server/loadRootComponents.js +1 -1
  1031. package/server/middlewareChain.ts +270 -0
  1032. package/server/mqtt.ts +35 -26
  1033. package/server/nodeName.ts +3 -1
  1034. package/server/operationsServer.ts +85 -10
  1035. package/server/serverHelpers/Headers.ts +10 -8
  1036. package/server/serverHelpers/JSONStream.ts +15 -5
  1037. package/server/serverHelpers/Request.ts +370 -13
  1038. package/server/serverHelpers/contentTypes.ts +42 -11
  1039. package/server/serverHelpers/multipartParser.ts +152 -0
  1040. package/server/serverHelpers/progressEmitter.ts +110 -0
  1041. package/server/serverHelpers/serverHandlers.js +43 -7
  1042. package/server/serverHelpers/serverUtilities.ts +40 -30
  1043. package/server/static.ts +9 -6
  1044. package/server/status/index.ts +2 -2
  1045. package/server/storageReclamation.ts +39 -2
  1046. package/server/threads/itc.js +7 -4
  1047. package/server/threads/manageThreads.js +100 -26
  1048. package/server/threads/socketRouter.ts +12 -275
  1049. package/server/threads/threadServer.js +345 -105
  1050. package/server/threads/workerProcessGuard.ts +93 -0
  1051. package/server/throttle.ts +18 -0
  1052. package/sqlTranslator/{SelectValidator.js → SelectValidator.ts} +41 -49
  1053. package/sqlTranslator/{alasqlFunctionImporter.js → alasqlFunctionImporter.ts} +5 -5
  1054. package/sqlTranslator/{deleteTranslator.js → deleteTranslator.ts} +13 -18
  1055. package/sqlTranslator/{index.js → index.ts} +30 -33
  1056. package/sqlTranslator/{sql_statement_bucket.js → sql_statement_bucket.ts} +49 -20
  1057. package/static/README.md +10 -9
  1058. package/static/defaultConfig.yaml +0 -1
  1059. package/studio/web/assets/{index-CybLScHg.js → index-Dqr9oVhe.js} +5 -5
  1060. package/studio/web/assets/index-Dqr9oVhe.js.map +1 -0
  1061. package/studio/web/assets/{index.lazy-DKx5-iXF.js → index.lazy-CpKcKb7M.js} +2 -2
  1062. package/studio/web/assets/{index.lazy-DKx5-iXF.js.map → index.lazy-CpKcKb7M.js.map} +1 -1
  1063. package/studio/web/assets/{profile-BOjes0Wl.js → profile-C1cujdsg.js} +2 -2
  1064. package/studio/web/assets/{profile-BOjes0Wl.js.map → profile-C1cujdsg.js.map} +1 -1
  1065. package/studio/web/assets/{status-EWKUIrjT.js → status-CTiIIQlY.js} +2 -2
  1066. package/studio/web/assets/{status-EWKUIrjT.js.map → status-CTiIIQlY.js.map} +1 -1
  1067. package/studio/web/index.html +1 -1
  1068. package/upgrade/{UpgradeObjects.js → UpgradeObjects.ts} +3 -6
  1069. package/upgrade/directives/5-1-0.ts +89 -0
  1070. package/upgrade/directives/{directivesController.js → directivesController.ts} +16 -16
  1071. package/upgrade/{directivesManager.js → directivesManager.ts} +7 -11
  1072. package/upgrade/{upgradePrompt.js → upgradePrompt.ts} +6 -54
  1073. package/upgrade/{upgradeUtilities.js → upgradeUtilities.ts} +3 -7
  1074. package/utility/{OperationFunctionCaller.js → OperationFunctionCaller.ts} +7 -7
  1075. package/utility/{assignCmdEnvVariables.js → assignCmdEnvVariables.ts} +6 -8
  1076. package/utility/{common_utils.js → common_utils.ts} +113 -139
  1077. package/utility/environment/{environmentManager.js → environmentManager.ts} +34 -33
  1078. package/utility/environment/systemInformation.ts +18 -4
  1079. package/utility/errors/{commonErrors.js → commonErrors.ts} +9 -9
  1080. package/utility/errors/{hdbError.js → hdbError.ts} +39 -45
  1081. package/utility/expandEnvVar.ts +110 -0
  1082. package/utility/functions/geo.js +2 -2
  1083. package/utility/functions/sql/alaSQLExtension.js +1 -1
  1084. package/utility/globalSchema.ts +30 -0
  1085. package/utility/hdbTerms.ts +54 -1
  1086. package/utility/install/checkJWTTokensExist.js +1 -1
  1087. package/utility/install/{installer.js → installer.ts} +66 -42
  1088. package/utility/installation.ts +2 -2
  1089. package/utility/lmdb/{DBIDefinition.js → DBIDefinition.ts} +4 -1
  1090. package/utility/lmdb/{DeleteRecordsResponseObject.js → DeleteRecordsResponseObject.ts} +2 -1
  1091. package/utility/lmdb/{InsertRecordsResponseObject.js → InsertRecordsResponseObject.ts} +2 -1
  1092. package/utility/lmdb/OpenDBIObject.ts +57 -0
  1093. package/utility/lmdb/{OpenEnvironmentObject.js → OpenEnvironmentObject.ts} +19 -6
  1094. package/utility/lmdb/{UpdateRecordsResponseObject.js → UpdateRecordsResponseObject.ts} +2 -1
  1095. package/utility/lmdb/{UpsertRecordsResponseObject.js → UpsertRecordsResponseObject.ts} +2 -1
  1096. package/utility/lmdb/{cleanLMDBMap.js → cleanLMDBMap.ts} +5 -5
  1097. package/utility/lmdb/{commonUtility.js → commonUtility.ts} +13 -21
  1098. package/utility/lmdb/{deleteUtility.js → deleteUtility.ts} +8 -12
  1099. package/utility/lmdb/{environmentUtility.js → environmentUtility.ts} +43 -52
  1100. package/utility/lmdb/{searchCursorFunctions.js → searchCursorFunctions.ts} +12 -26
  1101. package/utility/lmdb/{searchUtility.js → searchUtility.ts} +75 -64
  1102. package/utility/lmdb/{terms.js → terms.ts} +10 -23
  1103. package/utility/lmdb/{writeUtility.js → writeUtility.ts} +37 -22
  1104. package/utility/logging/{harper_logger.js → harper_logger.ts} +137 -90
  1105. package/utility/logging/{logRotator.js → logRotator.ts} +15 -18
  1106. package/utility/logging/logger.ts +1 -1
  1107. package/utility/logging/{readLog.js → readLog.ts} +19 -19
  1108. package/utility/logging/{transactionLog.js → transactionLog.ts} +10 -14
  1109. package/utility/{mount_hdb.js → mount_hdb.ts} +15 -16
  1110. package/utility/{npmUtilities.js → npmUtilities.ts} +14 -17
  1111. package/utility/{operation_authorization.js → operation_authorization.ts} +173 -124
  1112. package/utility/packageUtils.js +7 -16
  1113. package/utility/password.ts +1 -1
  1114. package/utility/processManagement/processManagement.js +2 -2
  1115. package/utility/processManagement/servicesConfig.js +1 -1
  1116. package/utility/{signalling.js → signalling.ts} +6 -11
  1117. package/utility/watcherFallback.ts +74 -0
  1118. package/validation/analyticsValidator.ts +44 -0
  1119. package/validation/{bulkDeleteValidator.js → bulkDeleteValidator.ts} +5 -5
  1120. package/validation/{check_permissions.js → check_permissions.ts} +3 -3
  1121. package/validation/{common_validators.js → common_validators.ts} +12 -24
  1122. package/validation/{configValidator.js → configValidator.ts} +114 -18
  1123. package/validation/{deleteValidator.js → deleteValidator.ts} +5 -5
  1124. package/validation/{fileLoadValidator.js → fileLoadValidator.ts} +12 -19
  1125. package/validation/{insertValidator.js → insertValidator.ts} +5 -5
  1126. package/validation/{installValidator.js → installValidator.ts} +8 -8
  1127. package/validation/{readLogValidator.js → readLogValidator.ts} +10 -10
  1128. package/validation/{role_validation.js → role_validation.ts} +26 -32
  1129. package/validation/{schemaMetadataValidator.js → schemaMetadataValidator.ts} +5 -11
  1130. package/validation/{searchValidator.js → searchValidator.ts} +12 -11
  1131. package/validation/statusValidator.ts +1 -1
  1132. package/validation/{transactionLogValidator.js → transactionLogValidator.ts} +4 -9
  1133. package/validation/{user_validation.js → user_validation.ts} +4 -10
  1134. package/validation/{validationWrapper.js → validationWrapper.ts} +3 -9
  1135. package/bin/cliOperations.js +0 -159
  1136. package/bin/lite.js +0 -5
  1137. package/dataLayer/harperBridge/BridgeMethods.js +0 -85
  1138. package/studio/web/assets/index-CybLScHg.js.map +0 -1
  1139. package/utility/globalSchema.js +0 -35
  1140. package/utility/lmdb/OpenDBIObject.js +0 -31
@@ -6,7 +6,8 @@
6
6
 
7
7
  import { CONFIG_PARAMS, OPERATIONS_ENUM, SYSTEM_TABLE_NAMES, SYSTEM_SCHEMA_NAME } from '../utility/hdbTerms.ts';
8
8
  import { type Database } from 'lmdb';
9
- import { getIndexedValues } from '../utility/lmdb/commonUtility.js';
9
+ import { Script } from 'node:vm';
10
+ import { getIndexedValues } from '../utility/lmdb/commonUtility.ts';
10
11
  import { getThisNodeId, exportIdMapping } from './nodeIdMapping.ts';
11
12
  import lodash from 'lodash';
12
13
  import { ExtendedIterable, SKIP } from '@harperfast/extended-iterable';
@@ -25,10 +26,10 @@ import lmdbProcessRows from '../dataLayer/harperBridge/lmdbBridge/lmdbUtility/lm
25
26
  import { Resource, transformForSelect } from './Resource.ts';
26
27
  import { when, promiseNormalize } from '../utility/when.ts';
27
28
  import { DatabaseTransaction, ImmediateTransaction, TRANSACTION_STATE } from './DatabaseTransaction.ts';
28
- import * as envMngr from '../utility/environment/environmentManager.js';
29
+ import * as envMngr from '../utility/environment/environmentManager.ts';
29
30
  import { addSubscription } from './transactionBroadcast.ts';
30
- import { handleHDBError, ClientError, ServerError, AccessViolation } from '../utility/errors/hdbError.js';
31
- import * as signalling from '../utility/signalling.js';
31
+ import { handleHDBError, ClientError, ServerError, AccessViolation } from '../utility/errors/hdbError.ts';
32
+ import * as signalling from '../utility/signalling.ts';
32
33
  import { SchemaEventMsg, UserEventMsg } from '../server/threads/itc.js';
33
34
  import { databases, table } from './databases.ts';
34
35
  import {
@@ -38,6 +39,7 @@ import {
38
39
  flattenKey,
39
40
  COERCIBLE_OPERATORS,
40
41
  executeConditions,
42
+ resolveComparator,
41
43
  } from './search.ts';
42
44
  import { logger } from '../utility/logging/logger.ts';
43
45
  import { Addition, assignTrackedAccessors, updateAndFreeze, hasChanges, GenericTrackedObject } from './tracked.ts';
@@ -45,7 +47,8 @@ import { transaction, contextStorage } from './transaction.ts';
45
47
  import { MAXIMUM_KEY, writeKey, compareKeys } from 'ordered-binary';
46
48
  import { getWorkerIndex, getWorkerCount } from '../server/threads/manageThreads.js';
47
49
  import { HAS_BLOBS, auditRetention, removeAuditEntry } from './auditStore.ts';
48
- import { autoCast, autoCastBooleanStrict } from '../utility/common_utils.js';
50
+ import { buildEmbedBefore, createDefaultEmbedder, type EmbedAttribute, type Embedder } from './models/embedHook.ts';
51
+ import { autoCast, autoCastBooleanStrict } from '../utility/common_utils.ts';
49
52
  import {
50
53
  recordUpdater,
51
54
  removeEntry,
@@ -61,11 +64,12 @@ import fs from 'node:fs';
61
64
  import { Blob, deleteBlobsInObject, findBlobsInObject, startPreCommitBlobsForRecord } from './blob.ts';
62
65
  import { onStorageReclamation } from '../server/storageReclamation.ts';
63
66
  import { RequestTarget } from './RequestTarget.ts';
64
- import harperLogger from '../utility/logging/harper_logger.js';
67
+ import harperLogger from '../utility/logging/harper_logger.ts';
65
68
  import { throttle } from '../server/throttle.ts';
66
69
  import { RocksDatabase } from '@harperfast/rocksdb-js';
67
70
  import { LMDBTransaction, ImmediateTransaction as ImmediateLMDBTransaction } from './LMDBTransaction';
68
71
  import { contentTypes } from '../server/serverHelpers/contentTypes';
72
+ import { type JsonSchemaFragment, projectAttributesToProperties } from './jsonSchemaTypes.ts';
69
73
 
70
74
  const { sortBy } = lodash;
71
75
  const { validateAttribute } = lmdbProcessRows;
@@ -73,16 +77,28 @@ const { validateAttribute } = lmdbProcessRows;
73
77
  export type Attribute = {
74
78
  name: string;
75
79
  type: 'ID' | 'Int' | 'Float' | 'Long' | 'String' | 'Boolean' | 'Date' | 'Bytes' | 'Any' | 'BigInt' | 'Blob' | string;
80
+ description?: string;
81
+ hidden?: boolean;
76
82
  assignCreatedTime?: boolean;
77
83
  assignUpdatedTime?: boolean;
78
84
  nullable?: boolean;
79
85
  expiresAt?: boolean;
80
86
  isPrimaryKey?: boolean;
81
- indexed?: unknown;
82
- relationship?: unknown;
83
- computed?: unknown;
87
+ indexed?: any;
88
+ relationship?: any;
89
+ computed?: any;
90
+ resolve?: any;
91
+ computedFromExpression?: any;
92
+ embed?: { source: string; model: string };
93
+ version?: any;
84
94
  properties?: Array<Attribute>;
85
95
  elements?: Attribute;
96
+ sealed?: boolean;
97
+
98
+ definition?: any;
99
+ set?: any;
100
+ enumerable?: boolean;
101
+ select?: any;
86
102
  };
87
103
 
88
104
  type MaybePromise<T> = T | Promise<T>;
@@ -91,13 +107,14 @@ const NULL_WITH_TIMESTAMP = new Uint8Array(9);
91
107
  NULL_WITH_TIMESTAMP[8] = 0xc0; // null
92
108
  const UNCACHEABLE_TIMESTAMP = Infinity; // we use this when dynamic content is accessed that we can't safely cache, and this prevents earlier timestamps from change the "last" modification
93
109
  const RECORD_PRUNING_INTERVAL = 60000; // one minute
110
+ const CACHEABLE_STATUS_CODES = new Set([200, 203, 204, 206, 300, 301, 308, 404, 405, 410, 414, 501]);
94
111
  envMngr.initSync();
95
112
  const LMDB_PREFETCH_WRITES = envMngr.get(CONFIG_PARAMS.STORAGE_PREFETCHWRITES);
96
113
  const LOCK_TIMEOUT = 10000;
97
-
98
- // True only for frozen plain/record objects (the immutable decoded records). Excludes Buffers,
99
- // TypedArrays, ArrayBuffers and primitives/null, which must not be shallow-copied via spread (that
100
- // would corrupt binary values). Used to decide when to copy-on-mutate before stamping a record.
114
+ // A frozen record we may need to copy-on-mutate before stamping it (records are immutable — decoded
115
+ // records are frozen and 5.2 record caching relies on it). Only plain/record objects qualify: never
116
+ // a Buffer/typed-array (spreading would corrupt the binary into a {0:.., 1:..} object) or a primitive
117
+ // (which reports as frozen and would spread into character/index keys).
101
118
  function isFrozenRecordObject(value: any): boolean {
102
119
  return (
103
120
  value !== null &&
@@ -141,6 +158,9 @@ export interface Table {
141
158
  indexingOperations?: Promise<void>;
142
159
  source?: new () => ResourceInterface;
143
160
  Transaction: ReturnType<typeof makeTable>;
161
+ description?: string;
162
+ properties?: Record<string, JsonSchemaFragment>;
163
+ hidden?: boolean;
144
164
  }
145
165
  type ResidencyDefinition = number | string[] | void;
146
166
 
@@ -149,6 +169,7 @@ type ResidencyDefinition = number | string[] | void;
149
169
  * Instances of the returned class are Resource instances, intended to provide a consistent view or transaction of the table
150
170
  * @param options
151
171
  */
172
+ // #section: setup-and-factory
152
173
  export function makeTable(options) {
153
174
  const {
154
175
  primaryKey,
@@ -164,17 +185,23 @@ export function makeTable(options) {
164
185
  sealed,
165
186
  splitSegments,
166
187
  replicate,
188
+ description,
189
+ hidden,
167
190
  } = options;
168
191
  let { expirationMS: expirationMs, evictionMS: evictionMs, audit, trackDeletes } = options;
169
192
  evictionMs ??= 0;
170
- let { attributes }: { attributes: Attribute[] } = options;
193
+ let { attributes, properties }: { attributes: Attribute[]; properties?: Record<string, JsonSchemaFragment> } =
194
+ options;
171
195
  if (!attributes) attributes = [];
196
+ if (!properties) properties = projectAttributesToProperties(attributes);
172
197
  const updateRecord = recordUpdater(primaryStore, tableId, auditStore);
173
198
  let sourceLoad: any; // if a source has a load function (replicator), record it here
174
199
  let hasSourceGet: any;
175
- let primaryKeyAttribute: Attribute = {};
200
+ let primaryKeyAttribute: Attribute | undefined;
176
201
  let lastEvictionCompletion: Promise<void> = Promise.resolve();
177
- let createdTimeProperty: Attribute, updatedTimeProperty: Attribute, expiresAtProperty: Attribute;
202
+ let createdTimeProperty: Attribute | undefined,
203
+ updatedTimeProperty: Attribute | undefined,
204
+ expiresAtProperty: Attribute | undefined;
178
205
  for (const attribute of attributes) {
179
206
  if (attribute.assignCreatedTime || attribute.name === '__createdtime__') createdTimeProperty = attribute;
180
207
  if (attribute.assignUpdatedTime || attribute.name === '__updatedtime__') updatedTimeProperty = attribute;
@@ -241,6 +268,7 @@ export function makeTable(options) {
241
268
  #savingOperation?: any; // operation for the record is currently being saved
242
269
 
243
270
  declare getProperty: (name: string) => any;
271
+ // #section: static-config
244
272
  static name = tableName; // for display/debugging purposes
245
273
  static primaryStore = primaryStore;
246
274
  static auditStore = auditStore;
@@ -252,6 +280,11 @@ export function makeTable(options) {
252
280
  static databasePath = databasePath;
253
281
  static databaseName = databaseName;
254
282
  static attributes = attributes;
283
+ static description = description;
284
+ static properties = properties;
285
+ static hidden = hidden;
286
+ static outputSchemas: { [verb: string]: JsonSchemaFragment } | undefined;
287
+ static mcp: { annotations?: { [verb: string]: any } } | undefined;
255
288
  static replicate = replicate;
256
289
  static sealed = sealed;
257
290
  static splitSegments = splitSegments ?? true;
@@ -259,6 +292,11 @@ export function makeTable(options) {
259
292
  static updatedTimeProperty = updatedTimeProperty;
260
293
  static propertyResolvers;
261
294
  static userResolvers = {};
295
+ // `@embed` hook registry. `userSetEmbedders` records names set explicitly via
296
+ // `setEmbedAttribute` so a schema reload refreshes defaults without clobbering them.
297
+ static userEmbedders: { [name: string]: Embedder } = {};
298
+ static userSetEmbedders: Set<string> = new Set();
299
+ static embedAttributes: EmbedAttribute[] = (attributes as any[]).filter((a) => a?.embed);
262
300
  static source?: typeof TableResource;
263
301
  declare static sourceOptions: any;
264
302
  declare static intermediateSource: boolean;
@@ -276,6 +314,7 @@ export function makeTable(options) {
276
314
  * @param options
277
315
  * @returns
278
316
  */
317
+ // #section: resource-registry
279
318
  static sourcedFrom(source, options) {
280
319
  // define a source for retrieving invalidated entries for caching purposes
281
320
  if (options) {
@@ -521,10 +560,10 @@ export function makeTable(options) {
521
560
  }
522
561
  });
523
562
  if (txnInProgress) txnInProgress.committed = commitResolution;
524
- if (userRoleUpdate && commitResolution && !commitResolution?.waitingForUserChange) {
563
+ if (userRoleUpdate && commitResolution && !(commitResolution as any).waitingForUserChange) {
525
564
  // if the user role changed, asynchronously signal the user change (but don't block this function)
526
565
  commitResolution.then(() => signalling.signalUserChange(new UserEventMsg(process.pid)));
527
- commitResolution.waitingForUserChange = true; // only need to send one signal per transaction
566
+ (commitResolution as any).waitingForUserChange = true; // only need to send one signal per transaction
528
567
  }
529
568
 
530
569
  if (event.onCommit) {
@@ -572,11 +611,7 @@ export function makeTable(options) {
572
611
  }
573
612
  return resource;
574
613
  }
575
- _loadRecord<Record extends object = any>(
576
- target: RequestTarget,
577
- request: Context,
578
- resourceOptions?: any
579
- ): MaybePromise<TableResource<Record>> {
614
+ _loadRecord(target: RequestTarget, request: Context, resourceOptions?: any): MaybePromise<TableResource<Record>> {
580
615
  const id = target && typeof target === 'object' ? target.id : target;
581
616
  if (id == null) return this;
582
617
  checkValidId(id);
@@ -605,9 +640,10 @@ export function makeTable(options) {
605
640
  // return 504 (rather than 404) if there is no content and the cache-control header
606
641
  // dictates not to go to source
607
642
  if (!this.doesExist()) throw new ServerError('Entry is not cached', 504);
643
+ if (hasSourceGet && target) target.loadedFromSource = false; // mark it as cached
608
644
  } else if (resourceOptions?.ensureLoaded) {
609
645
  const loadingFromSource = ensureLoadedFromSource(
610
- this.constructor.source,
646
+ (this.constructor as any).source,
611
647
  id,
612
648
  entry,
613
649
  request,
@@ -616,7 +652,7 @@ export function makeTable(options) {
616
652
  );
617
653
  if (loadingFromSource) {
618
654
  txn?.disregardReadTxn(); // this could take some time, so don't keep the transaction open if possible
619
- return when(loadingFromSource, (entry) => {
655
+ return when(loadingFromSource as Promise<Entry>, (entry) => {
620
656
  TableResource._updateResource(this, entry);
621
657
  return this;
622
658
  });
@@ -642,19 +678,20 @@ export function makeTable(options) {
642
678
  */
643
679
  ensureLoaded() {
644
680
  const loadedFromSource = ensureLoadedFromSource(
645
- this.constructor.source,
681
+ (this.constructor as any).source,
646
682
  this.getId(),
647
683
  this.#entry,
648
684
  this.getContext()
649
685
  );
650
686
  if (loadedFromSource) {
651
- return when(loadedFromSource, (entry) => {
687
+ return when(loadedFromSource as Promise<Entry>, (entry) => {
652
688
  this.#entry = entry;
653
689
  this.#record = entry.value;
654
690
  this.#version = entry.version;
655
691
  });
656
692
  }
657
693
  }
694
+ // #section: lifecycle-admin
658
695
  static getNewId(): any {
659
696
  const type = primaryKeyAttribute?.type;
660
697
  // the default Resource behavior is to return a GUID, but for a table we can return incrementing numeric keys if the type is (or can be) numeric
@@ -954,19 +991,13 @@ export function makeTable(options) {
954
991
  new SchemaEventMsg(process.pid, OPERATIONS_ENUM.DROP_TABLE, databaseName, tableName)
955
992
  );
956
993
  }
957
- /**
958
- * This retrieves the data of this resource. By default, with no argument, just return `this`.
959
- */
960
- get(): TableResource<Record> | undefined;
994
+ // #section: read-path
961
995
  /**
962
996
  * This retrieves the data of this resource.
963
997
  * @param target - If included, is an identifier/query that specifies the requested target to retrieve and query
964
998
  */
965
- get(target: RequestTargetOrId): Record | AsyncIterable<Record> | Promise<Record | AsyncIterable<Record>>;
966
- get(
967
- target?: RequestTargetOrId
968
- ): TableResource<Record> | undefined | Record | AsyncIterable<Record> | Promise<Record | AsyncIterable<Record>> {
969
- const constructor: Resource = this.constructor;
999
+ get(target?: any): any {
1000
+ const constructor: any = this.constructor;
970
1001
  if (typeof target === 'string' && constructor.loadAsInstance !== false) return this.getProperty(target);
971
1002
  if (isSearchTarget(target)) {
972
1003
  // go back to the static search method so it gets a chance to override
@@ -984,7 +1015,7 @@ export function makeTable(options) {
984
1015
  recordCount: undefined,
985
1016
  estimatedRecordRange: undefined,
986
1017
  };
987
- if (this.getContext()?.includeExpensiveRecordCountEstimates) {
1018
+ if ((this.getContext() as any)?.includeExpensiveRecordCountEstimates) {
988
1019
  return TableResource.getRecordCount().then((recordCount) => {
989
1020
  description.recordCount = recordCount.recordCount;
990
1021
  description.estimatedRecordRange = recordCount.estimatedRange;
@@ -994,7 +1025,7 @@ export function makeTable(options) {
994
1025
  return description;
995
1026
  }
996
1027
  if (target !== undefined && constructor.loadAsInstance === false) {
997
- const context = this.getContext();
1028
+ const context: any = this.getContext();
998
1029
  const txn = txnForContext(context);
999
1030
  const readTxn = txn.getReadTxn();
1000
1031
  if (readTxn?.isDone) {
@@ -1003,7 +1034,7 @@ export function makeTable(options) {
1003
1034
  const id = requestTargetToId(target);
1004
1035
  checkValidId(id);
1005
1036
  let allowed = true;
1006
- if (target.checkPermission) {
1037
+ if ((target as any)?.checkPermission) {
1007
1038
  // requesting authorization verification
1008
1039
  allowed = this.allowRead(context.user, target, context);
1009
1040
  }
@@ -1063,11 +1094,12 @@ export function makeTable(options) {
1063
1094
  }
1064
1095
  return promiseNormalize(record, target);
1065
1096
  }
1066
- if (this.doesExist() || target?.ensureLoaded === false || this.getContext()?.returnNonexistent) {
1097
+ if (this.doesExist() || target?.ensureLoaded === false || (this.getContext() as any)?.returnNonexistent) {
1067
1098
  return this;
1068
1099
  }
1069
1100
  return undefined;
1070
1101
  }
1102
+ // #section: authz-hooks
1071
1103
  /**
1072
1104
  * Determine if the user is allowed to get/read data from the current resource
1073
1105
  */
@@ -1081,20 +1113,20 @@ export function makeTable(options) {
1081
1113
  // If attribute permissions are defined, we need to ensure there is a select that only returns the attributes the user has permission to
1082
1114
  // or if there are relationships, we need to ensure that the user has permission to read from the related table
1083
1115
  // Note that if we do not have a select, we do not return any relationships by default.
1084
- if (!target) target = {};
1116
+ if (!target) target = {} as any;
1085
1117
  if (select) {
1086
1118
  const selectArray = Array.isArray(select) ? select : [select];
1087
1119
  const attrsForType = attribute_permissions?.length > 0 && attributesAsObject(attribute_permissions, 'read');
1088
- target.select = selectArray
1089
- .map((property) => {
1120
+ (target as any).select = selectArray
1121
+ .map((property: any) => {
1090
1122
  const propertyName = property.name || property;
1091
1123
  if (!attrsForType || attrsForType[propertyName]) {
1092
1124
  const relatedTable = propertyResolvers[propertyName]?.definition?.tableClass;
1093
1125
  if (relatedTable) {
1094
1126
  // if there is a related table, we need to ensure the user has permission to read from that table and that attributes are properly restricted
1095
1127
  if (!property.name) property = { name: property };
1096
- if (!property.checkPermission && target.checkPermission)
1097
- property.checkPermission = target.checkPermission;
1128
+ if (!property.checkPermission && (target as any).checkPermission)
1129
+ property.checkPermission = (target as any).checkPermission;
1098
1130
  if (!relatedTable.prototype.allowRead.call(null, user, property, context)) return false;
1099
1131
  if (!property.select) return property.name; // no select was applied, just return the name
1100
1132
  }
@@ -1178,6 +1210,7 @@ export function makeTable(options) {
1178
1210
  return !!tablePermission?.delete && checkContextPermissions(context);
1179
1211
  }
1180
1212
 
1213
+ // #section: write-path-public
1181
1214
  /**
1182
1215
  * Start updating a record. The returned resource will record changes which are written
1183
1216
  * once the corresponding transaction is committed. These changes can (eventually) include CRDT type operations.
@@ -1227,29 +1260,29 @@ export function makeTable(options) {
1227
1260
  // updates that were passed into this method
1228
1261
  let allowed = true;
1229
1262
  if (target == undefined) throw new TypeError('Can not put a record without a target');
1230
- if (target.checkPermission) {
1263
+ if ((target as any)?.checkPermission) {
1231
1264
  // requesting authorization verification
1232
- allowed = this.allowUpdate(context.user, updates, context);
1265
+ allowed = this.allowUpdate((context as any).user, updates, context);
1233
1266
  }
1234
1267
  return when(allowed, (allowed) => {
1235
1268
  if (!allowed) {
1236
- throw new AccessViolation(context.user);
1269
+ throw new AccessViolation((context as any).user);
1237
1270
  }
1238
1271
  let loading: Promise<any>;
1239
- if (!this.#entry && this.constructor.loadAsInstance === false) {
1272
+ if (!this.#entry && (this.constructor as any).loadAsInstance === false) {
1240
1273
  // load the record if it hasn't been done yet
1241
1274
  loading = this._loadRecord(target, context, { ensureLoaded: true, async: true }) as Promise<any>;
1242
1275
  }
1243
1276
  return when(loading, () => {
1244
1277
  this.#changes = updates;
1245
- this._writeUpdate(id, this.#changes, false);
1246
- return this;
1278
+ // `when` awaits the embed hook (when `@embed` is active) before resolving,
1279
+ // so the caller's `save()` doesn't run before the write is staged.
1280
+ return when(this._writeUpdate(id, this.#changes, false), () => this);
1247
1281
  });
1248
1282
  });
1249
1283
  }
1250
1284
  }
1251
- this._writeUpdate(id, this.#changes, fullUpdate);
1252
- return this;
1285
+ return when(this._writeUpdate(id, this.#changes, fullUpdate), () => this);
1253
1286
  }
1254
1287
 
1255
1288
  /**
@@ -1257,29 +1290,31 @@ export function makeTable(options) {
1257
1290
  */
1258
1291
  save() {
1259
1292
  if (this.#savingOperation) {
1260
- const transaction = txnForContext(this.getContext());
1261
- if (transaction.save) {
1262
- try {
1263
- return transaction.save(this.#savingOperation);
1264
- } finally {
1265
- this.#savingOperation = null;
1266
- }
1293
+ try {
1294
+ return this.#saveOperation(this.#savingOperation);
1295
+ } finally {
1296
+ this.#savingOperation = null;
1267
1297
  }
1268
1298
  }
1269
1299
  }
1300
+ #saveOperation(operation: any) {
1301
+ const transaction = txnForContext(this.getContext());
1302
+ if (transaction.save) return transaction.save(operation) || operation.promise || operation.result;
1303
+ }
1270
1304
 
1271
- addTo(property, value) {
1305
+ addTo(property: any, value: any) {
1272
1306
  if (typeof value === 'number' || typeof value === 'bigint') {
1273
- if (this.#savingOperation?.fullUpdate) this.set(property, (+this.getProperty(property) || 0) + value);
1307
+ if (this.#savingOperation?.fullUpdate)
1308
+ (this as any).set(property, (+this.getProperty(property) || 0) + (value as any));
1274
1309
  else {
1275
- if (!this.#savingOperation) this.update();
1276
- this.set(property, new Addition(value));
1310
+ if (!this.#savingOperation) (this as any).update();
1311
+ (this as any).set(property, new Addition(value));
1277
1312
  }
1278
1313
  } else {
1279
1314
  throw new Error('Can not add a non-numeric value');
1280
1315
  }
1281
1316
  }
1282
- subtractFrom(property, value) {
1317
+ subtractFrom(property: any, value: any) {
1283
1318
  if (typeof value === 'number') {
1284
1319
  return this.addTo(property, -value);
1285
1320
  } else {
@@ -1307,11 +1342,11 @@ export function makeTable(options) {
1307
1342
  const context = this.getContext();
1308
1343
  if ((target as RequestTarget)?.checkPermission) {
1309
1344
  // requesting authorization verification
1310
- allowed = this.allowDelete(context.user, target as RequestTarget, context);
1345
+ allowed = this.allowDelete((context as any).user, target as any, context);
1311
1346
  }
1312
1347
  return when(allowed, (allowed: boolean) => {
1313
1348
  if (!allowed) {
1314
- throw new AccessViolation(context.user);
1349
+ throw new AccessViolation((context as any).user);
1315
1350
  }
1316
1351
  this._writeInvalidate(target ? requestTargetToId(target) : this.getId());
1317
1352
  });
@@ -1348,7 +1383,7 @@ export function makeTable(options) {
1348
1383
  INVALIDATED,
1349
1384
  audit,
1350
1385
  {
1351
- user: context?.user,
1386
+ user: (context as any)?.user,
1352
1387
  residencyId: options?.residencyId,
1353
1388
  nodeId: options?.nodeId,
1354
1389
  viaNodeId: options?.viaNodeId,
@@ -1373,8 +1408,8 @@ export function makeTable(options) {
1373
1408
  invalidated: true,
1374
1409
  entry: this.#entry,
1375
1410
  before:
1376
- this.constructor.source?.relocate && !context?.source
1377
- ? this.constructor.source.relocate.bind(this.constructor.source, id, undefined, context)
1411
+ (this.constructor as any).source?.relocate && !(context as any)?.source
1412
+ ? (this.constructor as any).source.relocate.bind((this.constructor as any).source, id, undefined, context)
1378
1413
  : undefined,
1379
1414
  commit: (txnTime, existingEntry, _retry, transaction: any) => {
1380
1415
  if (precedesExistingVersion(txnTime, existingEntry, options?.nodeId) <= 0) return;
@@ -1403,7 +1438,7 @@ export function makeTable(options) {
1403
1438
  metadata,
1404
1439
  audit,
1405
1440
  {
1406
- user: context.user,
1441
+ user: (context as any)?.user,
1407
1442
  residencyId: options.residencyId,
1408
1443
  nodeId: options.nodeId,
1409
1444
  viaNodeId: options?.viaNodeId,
@@ -1487,12 +1522,12 @@ export function makeTable(options) {
1487
1522
  committed = true;
1488
1523
  if (primaryStore.ifVersion) {
1489
1524
  // LMDB: committing the wrapper calls doneReadTxn(), removing it from trackedTxns
1490
- return lmdbTransaction.commit();
1525
+ return (lmdbTransaction as any).commit();
1491
1526
  }
1492
1527
  // RocksDB: eviction writes went directly into the raw transaction via options;
1493
1528
  // commit it directly, as DatabaseTransaction.commit() would abort it (no tracked writes).
1494
1529
  // Wrap in Promise.resolve so callers can rely on a thenable return regardless of engine.
1495
- return Promise.resolve((transaction as any).commit());
1530
+ return (transaction as any).commit();
1496
1531
  } finally {
1497
1532
  if (!committed) {
1498
1533
  // Skip path or thrown error: abort instead of committing so we don't apply
@@ -1514,77 +1549,82 @@ export function makeTable(options) {
1514
1549
  static operation(operation, context) {
1515
1550
  operation.table ||= tableName;
1516
1551
  operation.schema ||= databaseName;
1517
- return global.operation(operation, context);
1552
+ return (global as any).operation(operation, context);
1518
1553
  }
1519
1554
 
1520
1555
  /**
1521
1556
  * Store the provided record data into the current resource. This is not written
1522
1557
  * until the corresponding transaction is committed.
1523
1558
  */
1559
+ // @ts-expect-error The implementation intentionally uses a different argument order for back-compat
1524
1560
  put(
1525
1561
  target: RequestTarget,
1526
1562
  record: Record & RecordObject
1527
1563
  ): void | (Record & Partial<RecordObject>) | Promise<void | (Record & Partial<RecordObject>)> {
1528
1564
  if (record === undefined || record instanceof URLSearchParams) {
1529
- // legacy argument position, shift the arguments and go through the update method for back-compat
1530
- this.update(target, true);
1531
- return this.save();
1565
+ // legacy argument position, shift the arguments and go through the update method for back-compat.
1566
+ // `when` settles the embed hook before `save()` so the write is staged first.
1567
+ return when((this as any).update(target, true), () => this.save() as any) as any;
1532
1568
  } else {
1533
1569
  let allowed = true;
1534
1570
  if (target == undefined) throw new TypeError('Can not put a record without a target');
1535
1571
  const context = this.getContext();
1536
- if (target.checkPermission) {
1572
+ if ((target as any).checkPermission) {
1537
1573
  // requesting authorization verification
1538
- allowed = this.allowUpdate(context.user, record, context);
1574
+ allowed = this.allowUpdate((context as any).user, record, context);
1539
1575
  }
1540
1576
  return when(allowed, (allowed) => {
1541
1577
  if (!allowed) {
1542
- throw new AccessViolation(context.user);
1578
+ throw new AccessViolation((context as any).user);
1543
1579
  }
1544
1580
  // standard path, handle arrays as multiple updates, and otherwise do a direct update
1545
1581
  if (Array.isArray(record)) {
1546
- return Promise.all(
1547
- record.map((element) => {
1548
- const id = element[primaryKey];
1549
- this._writeUpdate(id, element, true);
1550
- return this.save();
1551
- })
1552
- );
1582
+ // Capture each element's operation synchronously (before any async `@embed`
1583
+ // hook resolves): `#savingOperation` is a single field that parallel writes
1584
+ // would otherwise clobber, so a deferred `save()` would commit the wrong op
1585
+ // — e.g. one element's save running before a later element's vector is written.
1586
+ const writes = record.map((element) => {
1587
+ const id = element[primaryKey];
1588
+ const writePromise = this._writeUpdate(id, element, true);
1589
+ const operation = this.#savingOperation;
1590
+ return when(writePromise, () => this.#saveOperation(operation));
1591
+ });
1592
+ this.#savingOperation = null;
1593
+ return Promise.all(writes) as any;
1553
1594
  } else {
1554
- const id = requestTargetToId(target);
1555
- this._writeUpdate(id, record, true);
1556
- return this.save();
1595
+ const id = requestTargetToId(target as any);
1596
+ return when(this._writeUpdate(id, record, true), () => this.save() as any);
1557
1597
  }
1558
- });
1598
+ }) as any;
1559
1599
  }
1560
1600
  // always return undefined
1561
1601
  }
1562
1602
 
1563
1603
  create(
1564
- target: RequestTarget,
1604
+ target: RequestTargetOrId,
1565
1605
  record: Partial<Record & RecordObject>
1566
1606
  ): void | (Record & Partial<RecordObject>) | Promise<Record & Partial<RecordObject>> {
1567
1607
  let allowed = true;
1568
1608
  const context = this.getContext();
1569
1609
  if (!record && !(target instanceof URLSearchParams)) {
1570
1610
  // single argument, shift arguments
1571
- record = target;
1611
+ record = target as any;
1572
1612
  target = undefined;
1573
1613
  }
1574
1614
  if (!record || typeof record !== 'object' || Array.isArray(record)) {
1575
1615
  throw new TypeError('Can not create a record without an object');
1576
1616
  }
1577
- if (target?.checkPermission) {
1617
+ if ((target as any)?.checkPermission) {
1578
1618
  // requesting authorization verification
1579
- allowed = this.allowCreate(context.user, record, context);
1619
+ allowed = this.allowCreate((context as any).user, record as any, context);
1580
1620
  }
1581
1621
  return when(allowed, (allowed) => {
1582
1622
  if (!allowed) {
1583
- throw new AccessViolation(context.user);
1623
+ throw new AccessViolation((context as any).user);
1584
1624
  }
1585
- let id = requestTargetToId(target) ?? record[primaryKey];
1625
+ let id = requestTargetToId(target as any) ?? record[primaryKey];
1586
1626
  if (id === undefined) {
1587
- id = this.constructor.getNewId();
1627
+ id = (this.constructor as any).getNewId();
1588
1628
  record[primaryKey] = id; // make this immediately available
1589
1629
  } else {
1590
1630
  const existing = primaryStore.getSync(id);
@@ -1592,9 +1632,11 @@ export function makeTable(options) {
1592
1632
  throw new ClientError('Record already exists', 409);
1593
1633
  }
1594
1634
  }
1595
- this._writeUpdate(id, record, true);
1596
- return record;
1597
- });
1635
+ // `_writeUpdate` may return a promise when an `@embed` directive
1636
+ // requires running an embedder before the per-write `commit(...)`
1637
+ // closure. `when()` passes through synchronous returns.
1638
+ return when(this._writeUpdate(id, record, true), () => record);
1639
+ }) as any;
1598
1640
  }
1599
1641
 
1600
1642
  // @ts-expect-error The implementation handles the possibility of target and recordUpdate being swapped
@@ -1603,39 +1645,39 @@ export function makeTable(options) {
1603
1645
  recordUpdate: Partial<Record & RecordObject>
1604
1646
  ): void | (Record & Partial<RecordObject>) | Promise<void | (Record & Partial<RecordObject>)> {
1605
1647
  if (recordUpdate === undefined || recordUpdate instanceof URLSearchParams) {
1606
- // legacy argument position, shift the arguments and go through the update method for back-compat
1607
- this.update(target, false);
1608
- return this.save();
1648
+ // legacy argument position, shift the arguments and go through the update method for back-compat.
1649
+ // `when` settles the embed hook before `save()` so the write is staged first.
1650
+ return when(this.update(target, false), () => this.save() as any) as any;
1609
1651
  } else {
1610
1652
  // standard path, ensure there is no return object
1611
1653
  return when(this.update(target, recordUpdate), () => {
1612
- return when(this.save(), () => undefined); // wait for the update and save, but return undefined
1613
- });
1654
+ return when(this.save() as any, () => undefined); // wait for the update and save, but return undefined
1655
+ }) as any;
1614
1656
  }
1615
1657
  }
1658
+ // #section: write-path-internals
1616
1659
  // perform the actual write operation; this may come from a user request to write (put, post, etc.), or
1617
1660
  // a notification that a write has already occurred in the canonical data source, we need to update our
1618
1661
  // local copy
1619
1662
  _writeUpdate(id: Id, recordUpdate: any, fullUpdate: boolean, options?: any) {
1620
1663
  const context = this.getContext();
1621
1664
  const transaction = txnForContext(context);
1622
-
1623
1665
  checkValidId(id);
1624
1666
  const entry = this.#entry ?? primaryStore.getEntry(id, { transaction: transaction.getReadTxn() });
1625
1667
  const writeToSource = () => {
1626
- if (!this.constructor.source || context?.source) return;
1668
+ if (!(this.constructor as any).source || (context as any)?.source) return;
1627
1669
  if (fullUpdate) {
1628
1670
  // full update is a put
1629
- if (this.constructor.source.put) {
1630
- return () => this.constructor.source.put(id, recordUpdate, context);
1671
+ if ((this.constructor as any).source.put) {
1672
+ return () => (this.constructor as any).source.put(id, recordUpdate, context);
1631
1673
  }
1632
1674
  } else {
1633
1675
  // incremental update
1634
- if (this.constructor.source.patch) {
1635
- return () => this.constructor.source.patch(id, recordUpdate, context);
1636
- } else if (this.constructor.source.put) {
1676
+ if ((this.constructor as any).source.patch) {
1677
+ return () => (this.constructor as any).source.patch(id, recordUpdate, context);
1678
+ } else if ((this.constructor as any).source.put) {
1637
1679
  // if this is incremental, but only have put, we can use that by generating the full record (at least the expected one)
1638
- return () => this.constructor.source.put(id, updateAndFreeze(this), context);
1680
+ return () => (this.constructor as any).source.put(id, updateAndFreeze(this), context);
1639
1681
  }
1640
1682
  }
1641
1683
  };
@@ -1644,13 +1686,13 @@ export function makeTable(options) {
1644
1686
  key: id,
1645
1687
  store: primaryStore,
1646
1688
  entry,
1647
- nodeName: context?.nodeName,
1689
+ nodeName: (context as any)?.nodeName,
1648
1690
  fullUpdate,
1649
1691
  deferSave: true,
1650
1692
  validate: (txnTime) => {
1651
1693
  if (!recordUpdate) recordUpdate = this.#changes;
1652
1694
  if (fullUpdate || (recordUpdate && hasChanges(this.#changes === recordUpdate ? this : recordUpdate))) {
1653
- if (!context?.source) {
1695
+ if (!(context as any)?.source) {
1654
1696
  transaction.checkOverloaded();
1655
1697
  // Records are intentionally immutable: decoded records are frozen (and 5.2 record
1656
1698
  // caching relies on it), so mutating in place would corrupt cached/shared state.
@@ -1693,7 +1735,7 @@ export function makeTable(options) {
1693
1735
  // TODO: else freeze after we have applied the changes
1694
1736
  }
1695
1737
  } else {
1696
- transaction.removeWrite?.(write);
1738
+ (transaction as any).removeWrite?.(write);
1697
1739
  return false;
1698
1740
  }
1699
1741
  },
@@ -1733,6 +1775,32 @@ export function makeTable(options) {
1733
1775
  // of the updates to the record to ensure consistency across the cluster
1734
1776
  // TODO: can the previous version be older, but even more previous version be newer?
1735
1777
  if (audit) {
1778
+ // A re-delivered out-of-order write (full-copy audit-replay re-delivers writes) must not have
1779
+ // its commutative ops re-folded. additionalAuditRefs is the record's own list of folded
1780
+ // out-of-order versions, read with read-your-writes consistency, so this skips the duplicate up
1781
+ // front — before the audit-log walk below, which can miss it: the walk stops at the depth cap, or
1782
+ // breaks early on a not-yet-visible audit entry, before reaching txnTime, and the keyed
1783
+ // transaction-log lookup it would otherwise use can lag a back-to-back re-delivery (that lag
1784
+ // silently double-applied the increment — #1137). This covers the re-delivery while the ref is
1785
+ // still on the record; a later in-order write rewrites the record and drops the ref (it survives
1786
+ // only as previousAdditionalAuditRefs on the audit log), so that case falls back to the
1787
+ // best-effort keyed lookup in the capped block below — see #1148. precedesExistingVersion(...)
1788
+ // === 0 is the identity tie: same version AND same node (the local node is id 0, so an undefined
1789
+ // options?.nodeId resolves to the same 0 the ref stored).
1790
+ if (
1791
+ existingEntry.additionalAuditRefs?.some(
1792
+ (ref) =>
1793
+ ref.version === txnTime &&
1794
+ precedesExistingVersion(
1795
+ txnTime,
1796
+ { version: txnTime, localTime: txnTime, key: id, nodeId: ref.nodeId },
1797
+ options?.nodeId
1798
+ ) === 0
1799
+ )
1800
+ ) {
1801
+ write.skipped = true;
1802
+ return; // out-of-order write already folded into this record
1803
+ }
1736
1804
  // incremental CRDT updates are only available with audit logging on
1737
1805
  let localTime = existingEntry.localTime;
1738
1806
  let auditedVersion = existingEntry.version;
@@ -1864,8 +1932,12 @@ export function makeTable(options) {
1864
1932
  // retained window are not layered in — but the authoritative full-copy record restores exact
1865
1933
  // convergence. Because we stopped before reaching txnTime, the inline duplicate detection in
1866
1934
  // the walk never ran; full-copy audit-replay re-delivers writes, and re-applying one would
1867
- // double-apply its commutative ops, so rule that out here with a single O(1) lookup at txnTime
1868
- // (RocksDB audit logs are keyed by version, and the cap is RocksDB-only).
1935
+ // double-apply its commutative ops. A re-delivered out-of-order write is already ruled out by
1936
+ // the additionalAuditRefs check at the top of this block; this keyed lookup is the best-effort
1937
+ // guard for the remaining case — a re-delivered write that was originally in-order (so it left
1938
+ // no ref) and is now deeper than the cap. It is best-effort because the transaction-log lookup
1939
+ // can intermittently miss an entry under load (tracked separately); the authoritative full-copy
1940
+ // record still restores exact convergence.
1869
1941
  logger.warn?.(
1870
1942
  'Out-of-order audit reconciliation exceeded depth cap; reconciling against most recent updates only',
1871
1943
  {
@@ -1921,7 +1993,7 @@ export function makeTable(options) {
1921
1993
  let recordToStore: any;
1922
1994
  if (fullUpdate && !incrementalUpdateToApply) recordToStore = recordUpdate;
1923
1995
  else {
1924
- if (this.constructor.loadAsInstance === false)
1996
+ if ((this.constructor as any).loadAsInstance === false)
1925
1997
  recordToStore = updateAndFreeze(existingRecord, incrementalUpdateToApply ?? recordUpdate);
1926
1998
  else {
1927
1999
  this.#record = existingRecord;
@@ -1932,7 +2004,8 @@ export function makeTable(options) {
1932
2004
  if (recordToStore && recordToStore.getRecord)
1933
2005
  throw new Error('Can not assign a record to a record, check for circular references');
1934
2006
  if (residencyId == undefined) {
1935
- if (entry?.residencyId) context.previousResidency = TableResource.getResidencyRecord(entry.residencyId);
2007
+ if (entry?.residencyId)
2008
+ (context as any).previousResidency = TableResource.getResidencyRecord(entry.residencyId);
1936
2009
  const residency = residencyFromFunction(TableResource.getResidency(recordToStore, context));
1937
2010
  if (residency) {
1938
2011
  if (!residency.includes(server.hostname)) {
@@ -1999,12 +2072,12 @@ export function makeTable(options) {
1999
2072
  audit,
2000
2073
  {
2001
2074
  omitLocalRecord,
2002
- user: context?.user,
2075
+ user: (context as any)?.user,
2003
2076
  residencyId,
2004
2077
  expiresAt,
2005
2078
  nodeId: options?.nodeId,
2006
2079
  viaNodeId: options?.viaNodeId,
2007
- originatingOperation: context?.originatingOperation,
2080
+ originatingOperation: (context as any)?.originatingOperation,
2008
2081
  transaction,
2009
2082
  tableToTrack: databaseName === 'system' ? null : options?.replay ? null : tableName, // don't track analytics on system tables
2010
2083
  additionalAuditRefs: additionalAuditRefs.length > 0 ? additionalAuditRefs : undefined,
@@ -2017,33 +2090,52 @@ export function makeTable(options) {
2017
2090
  },
2018
2091
  };
2019
2092
  this.#savingOperation = write;
2020
- write.beforeIntermediate = preCommitBlobsForRecordBefore(write, recordUpdate);
2021
- return transaction.addWrite(write);
2093
+ // `@embed` hook must run before `addWrite` so the embedder's vector is on the
2094
+ // record when `commit` runs. (The txn `before` slot runs after commit, which
2095
+ // suits blob writes but not embedding, where the vector must be present at commit.)
2096
+ // Known limitation of this write-time placement (a validate-time alternative was
2097
+ // tried and reverted as a Harper-foreign pattern): the embedder sees this write's
2098
+ // payload, before table validation — so a write that later fails validation still
2099
+ // calls the backend, and a tracked-instance mutation (update(id,{}); row.source=…;
2100
+ // save()) that sets the source via accessors after update() won't re-embed. A
2101
+ // resource-layer re-embed is the proper fix; tracked as a follow-up.
2102
+ const embedBefore = buildEmbedBefore(
2103
+ recordUpdate,
2104
+ context,
2105
+ options,
2106
+ TableResource.embedAttributes,
2107
+ TableResource.userEmbedders
2108
+ );
2109
+ const proceed = (): any => {
2110
+ write.beforeIntermediate = preCommitBlobsForRecordBefore(write, recordUpdate);
2111
+ return transaction.addWrite(write as any);
2112
+ };
2113
+ return embedBefore ? embedBefore().then(proceed) : proceed();
2022
2114
  }
2023
2115
 
2024
2116
  async delete(target: RequestTargetOrId): Promise<boolean> {
2025
2117
  if (isSearchTarget(target)) {
2026
2118
  target.select = ['$id']; // just get the primary key of each record so we can delete them
2027
2119
  for await (const entry of this.search(target)) {
2028
- this._writeDelete(entry.$id);
2120
+ this._writeDelete((entry as any).$id);
2029
2121
  }
2030
2122
  return true;
2031
2123
  }
2032
2124
  if (target) {
2033
2125
  let allowed = true;
2034
2126
  const context = this.getContext();
2035
- if (target.checkPermission) {
2127
+ if ((target as any)?.checkPermission) {
2036
2128
  // requesting authorization verification
2037
- allowed = this.allowDelete(context.user, target, context);
2129
+ allowed = this.allowDelete((context as any).user, target as any, context);
2038
2130
  }
2039
2131
  return when(allowed, (allowed: boolean) => {
2040
2132
  if (!allowed) {
2041
- throw new AccessViolation(context.user);
2133
+ throw new AccessViolation((context as any).user);
2042
2134
  }
2043
- const id = requestTargetToId(target);
2135
+ const id = requestTargetToId(target as any);
2044
2136
  this._writeDelete(id);
2045
2137
  return true;
2046
- });
2138
+ }) as any;
2047
2139
  }
2048
2140
  this._writeDelete(this.getId());
2049
2141
  return Boolean(this.#record);
@@ -2058,10 +2150,10 @@ export function makeTable(options) {
2058
2150
  key: id,
2059
2151
  store: primaryStore,
2060
2152
  entry,
2061
- nodeName: context?.nodeName,
2153
+ nodeName: (context as any)?.nodeName,
2062
2154
  before:
2063
- this.constructor.source?.delete && !context?.source
2064
- ? this.constructor.source.delete.bind(this.constructor.source, id, undefined, context)
2155
+ (this.constructor as any).source?.delete && !(context as any)?.source
2156
+ ? (this.constructor as any).source.delete.bind((this.constructor as any).source, id, undefined, context)
2065
2157
  : undefined,
2066
2158
  commit: (txnTime, existingEntry, retry, transaction: any) => {
2067
2159
  const existingRecord = existingEntry?.value;
@@ -2083,7 +2175,7 @@ export function makeTable(options) {
2083
2175
  0,
2084
2176
  audit,
2085
2177
  {
2086
- user: context?.user,
2178
+ user: (context as any)?.user,
2087
2179
  nodeId: options?.nodeId,
2088
2180
  viaNodeId: options?.viaNodeId,
2089
2181
  transaction,
@@ -2096,10 +2188,11 @@ export function makeTable(options) {
2096
2188
  removeEntry(primaryStore, existingEntry);
2097
2189
  }
2098
2190
  },
2099
- });
2191
+ } as any);
2100
2192
  return true;
2101
2193
  }
2102
2194
 
2195
+ // #section: search-query
2103
2196
  search(target: RequestTarget): AsyncIterable<Record & Partial<RecordObject>> {
2104
2197
  const context = this.getContext();
2105
2198
  const txn = txnForContext(context);
@@ -2107,14 +2200,14 @@ export function makeTable(options) {
2107
2200
  if (target.parseError) throw target.parseError; // if there was a parse error, we can throw it now
2108
2201
  if (target.checkPermission) {
2109
2202
  // requesting authorization verification
2110
- const allowed = this.allowRead(context.user, target, context);
2203
+ const allowed = this.allowRead((context as any).user, target, context);
2111
2204
  if (!allowed) {
2112
- throw new AccessViolation(context.user);
2205
+ throw new AccessViolation((context as any).user);
2113
2206
  }
2114
2207
  }
2115
2208
  if (context) context.lastModified = UNCACHEABLE_TIMESTAMP;
2116
2209
 
2117
- let conditions = target.conditions;
2210
+ let conditions: any = target.conditions;
2118
2211
  if (!conditions) conditions = Array.isArray(target) ? target : target[Symbol.iterator] ? Array.from(target) : [];
2119
2212
  else if (conditions.length === undefined) {
2120
2213
  conditions = conditions[Symbol.iterator] ? Array.from(conditions) : [conditions];
@@ -2132,7 +2225,7 @@ export function makeTable(options) {
2132
2225
  let orderAlignedCondition;
2133
2226
  const filtered = {};
2134
2227
 
2135
- function prepareConditions(conditions: Condition[], operator: string) {
2228
+ function prepareConditions(conditions: any[], operator: string) {
2136
2229
  // some validation:
2137
2230
  switch (operator) {
2138
2231
  case 'and':
@@ -2150,15 +2243,37 @@ export function makeTable(options) {
2150
2243
  condition.conditions = prepareConditions(condition.conditions, condition.operator);
2151
2244
  continue;
2152
2245
  }
2246
+ // Normalize `not_X` comparator forms passed in via structured queries.
2247
+ // The REST parser already does this, but programmatic callers may
2248
+ // pass `not_in`, `not_starts_with`, etc. directly.
2249
+ if (condition.comparator) {
2250
+ const resolved = resolveComparator(condition.comparator);
2251
+ if (resolved.negated) {
2252
+ condition.comparator = resolved.comparator;
2253
+ condition.negated = true;
2254
+ }
2255
+ }
2153
2256
  const attribute_name = condition[0] ?? condition.attribute;
2154
- const attribute = attribute_name == null ? primaryKeyAttribute : findAttribute(attributes, attribute_name);
2257
+ let attribute = attribute_name == null ? primaryKeyAttribute : findAttribute(attributes, attribute_name);
2258
+ if (!attribute && Array.isArray(attribute_name) && attribute_name.length > 1) {
2259
+ // Plain JSON nested path: the leaf may not be declared in the
2260
+ // schema. Fall back to the root attribute so we can validate
2261
+ // existence without requiring the inner structure to be typed.
2262
+ attribute = findAttribute(attributes, attribute_name[0]);
2263
+ }
2155
2264
  if (!attribute) {
2156
2265
  if (attribute_name != null && !target.allowConditionsOnDynamicAttributes)
2157
2266
  throw handleHDBError(new Error(), `${attribute_name} is not a defined attribute`, 404);
2158
2267
  } else if (attribute.type || COERCIBLE_OPERATORS[condition.comparator]) {
2159
- // Do auto-coercion or coercion as required by the attribute type
2160
- if (condition[1] === undefined) condition.value = coerceTypedValues(condition.value, attribute);
2161
- else condition[1] = coerceTypedValues(condition[1], attribute);
2268
+ // Do auto-coercion or coercion as required by the attribute type.
2269
+ // Skipped for nested paths into plain JSON — the root attribute's
2270
+ // type is not the leaf type, so coercion would be wrong.
2271
+ const isNestedPathRoot =
2272
+ Array.isArray(attribute_name) && attribute_name.length > 1 && !attribute.relationship;
2273
+ if (!isNestedPathRoot) {
2274
+ if (condition[1] === undefined) condition.value = coerceTypedValues(condition.value, attribute);
2275
+ else condition[1] = coerceTypedValues(condition[1], attribute);
2276
+ }
2162
2277
  }
2163
2278
  if (condition.chainedConditions) {
2164
2279
  if (condition.chainedConditions.length === 1 && (!condition.operator || condition.operator == 'and')) {
@@ -2188,7 +2303,7 @@ export function makeTable(options) {
2188
2303
  }
2189
2304
  const isGe = lower.comparator === 'ge' || lower.comparator === 'greater_than_equal';
2190
2305
  const isLe = upper.comparator === 'le' || upper.comparator === 'less_than_equal';
2191
- condition.comparator = (isGe ? 'ge' : 'gt') + (isLe ? 'le' : 'lt');
2306
+ condition.comparator = ((isGe ? 'ge' : 'gt') + (isLe ? 'le' : 'lt')) as any;
2192
2307
  condition.value = [lower.value, upper.value];
2193
2308
  } else throw new Error('Multiple chained conditions are not currently supported');
2194
2309
  }
@@ -2218,11 +2333,11 @@ export function makeTable(options) {
2218
2333
  let postOrdering;
2219
2334
  if (sort) {
2220
2335
  // TODO: Support index-assisted sorts of unions, which will require potentially recursively adding/modifying an order aligned condition and be able to recursively undo it if necessary
2221
- if (operator !== 'or') {
2336
+ if ((operator as any) !== 'or') {
2222
2337
  const attribute_name = sort.attribute;
2223
2338
  if (attribute_name == undefined) throw new ClientError('Sort requires an attribute');
2224
2339
  orderAlignedCondition = conditions.find(
2225
- (condition) => flattenKey(condition.attribute) === flattenKey(attribute_name)
2340
+ (condition) => flattenKey(condition.attribute as any) === flattenKey(attribute_name as any)
2226
2341
  );
2227
2342
  if (orderAlignedCondition) {
2228
2343
  // if there is a condition on the same attribute as the first sort, we can use it to align the sort
@@ -2233,7 +2348,7 @@ export function makeTable(options) {
2233
2348
  throw handleHDBError(
2234
2349
  new Error(),
2235
2350
  `${
2236
- Array.isArray(attribute_name) ? attribute_name.join('.') : attribute_name
2351
+ Array.isArray(attribute_name) ? (attribute_name as any).join('.') : attribute_name
2237
2352
  } is not a defined attribute`,
2238
2353
  404
2239
2354
  );
@@ -2245,7 +2360,7 @@ export function makeTable(options) {
2245
2360
  throw handleHDBError(
2246
2361
  new Error(),
2247
2362
  `${
2248
- Array.isArray(attribute_name) ? attribute_name.join('.') : attribute_name
2363
+ Array.isArray(attribute_name) ? (attribute_name as any).join('.') : attribute_name
2249
2364
  } is not indexed and not combined with any other conditions`,
2250
2365
  404
2251
2366
  );
@@ -2281,7 +2396,7 @@ export function makeTable(options) {
2281
2396
  operator,
2282
2397
  postOrdering,
2283
2398
  selectApplied: Boolean(select),
2284
- };
2399
+ } as any;
2285
2400
  }
2286
2401
  // we mark the read transaction as in use (necessary for a stable read
2287
2402
  // transaction, and we really don't care if the
@@ -2298,7 +2413,7 @@ export function makeTable(options) {
2298
2413
  (results: any[], filters: Function[]) => transformToEntries(results, select, context, readTxn, filters),
2299
2414
  filtered
2300
2415
  );
2301
- const ensure_loaded = target.ensureLoaded !== false;
2416
+ const ensure_loaded = (target as any).ensureLoaded !== false;
2302
2417
  const transformToRecord = TableResource.transformEntryForSelect(
2303
2418
  select,
2304
2419
  context,
@@ -2331,7 +2446,7 @@ export function makeTable(options) {
2331
2446
  const columns = [];
2332
2447
  for (const column of select) {
2333
2448
  if (column === '*') columns.push(...attributes.map((attribute) => attribute.name));
2334
- else columns.push(column.name || column);
2449
+ else columns.push((column as any).name || column);
2335
2450
  }
2336
2451
  return columns;
2337
2452
  }
@@ -2371,14 +2486,14 @@ export function makeTable(options) {
2371
2486
  ? entries[Symbol.asyncIterator]()
2372
2487
  : entries[Symbol.iterator]();
2373
2488
  let dbDone: boolean;
2374
- const dbOrderedAttribute = sort.dbOrderedAttribute;
2489
+ const dbOrderedAttribute = (sort as any).dbOrderedAttribute;
2375
2490
  let enqueuedEntryForNextGroup: any;
2376
2491
  let lastGroupingValue: any;
2377
2492
  let firstEntry = true;
2378
2493
  function createComparator(order: Sort) {
2379
2494
  const nextComparator = order.next && createComparator(order.next);
2380
2495
  const descending = order.descending;
2381
- context.sort = order; // make sure this is set to the current sort order
2496
+ (context as any).sort = order; // make sure this is set to the current sort order
2382
2497
  return (entryA, entryB) => {
2383
2498
  const a = getAttributeValue(entryA, order.attribute, context);
2384
2499
  const b = getAttributeValue(entryB, order.attribute, context);
@@ -2437,7 +2552,7 @@ export function makeTable(options) {
2437
2552
  ordered.push(entry);
2438
2553
  }
2439
2554
  } while (true);
2440
- if (sort.isGrouped) {
2555
+ if ((sort as any).isGrouped) {
2441
2556
  // TODO: Return grouped results
2442
2557
  }
2443
2558
  ordered.sort(comparator);
@@ -2465,8 +2580,8 @@ export function makeTable(options) {
2465
2580
  for (let i = 0; i < select.length; i++) {
2466
2581
  const column = select[i];
2467
2582
  let columnSort;
2468
- if (column.name === sort.attribute[0]) {
2469
- columnSort = column.sort || (column.sort = {});
2583
+ if ((column as any).name === sort.attribute[0]) {
2584
+ columnSort = (column as any).sort || ((column as any).sort = {});
2470
2585
  while (columnSort.next) columnSort = columnSort.next;
2471
2586
  columnSort.attribute = sort.attribute.slice(1);
2472
2587
  columnSort.descending = sort.descending;
@@ -2477,7 +2592,7 @@ export function makeTable(options) {
2477
2592
  attribute: sort.attribute.slice(1),
2478
2593
  descending: sort.descending,
2479
2594
  },
2480
- };
2595
+ } as any;
2481
2596
  }
2482
2597
  }
2483
2598
  }
@@ -2560,7 +2675,7 @@ export function makeTable(options) {
2560
2675
  this?.isSync,
2561
2676
  (entry: Entry) => entry
2562
2677
  );
2563
- if (entry?.then) return entry.then(transform.bind(this));
2678
+ if ((entry as any)?.then) return (entry as any).then(transform.bind(this));
2564
2679
  record = entry?.value;
2565
2680
  }
2566
2681
  if (
@@ -2670,12 +2785,22 @@ export function makeTable(options) {
2670
2785
  } else {
2671
2786
  value = record[attribute_name];
2672
2787
  if (value && typeof value === 'object' && attribute_name !== attribute) {
2673
- value = TableResource.transformEntryForSelect(
2788
+ const subTransform = TableResource.transformEntryForSelect(
2674
2789
  attribute.select || attribute,
2675
2790
  context,
2676
2791
  readTxn,
2677
2792
  null
2678
- )({ value });
2793
+ );
2794
+ // Plain JSON nested values: arrays project per-element so that
2795
+ // `select: [{ name: 'addresses', select: ['city'] }]` returns
2796
+ // `addresses: [{ city }, { city }]` rather than a single object.
2797
+ if (Array.isArray(value)) {
2798
+ value = value.map((item) =>
2799
+ item && typeof item === 'object' ? subTransform({ value: item } as any) : item
2800
+ );
2801
+ } else if (!(value instanceof Date)) {
2802
+ value = subTransform({ value } as any);
2803
+ }
2679
2804
  }
2680
2805
  }
2681
2806
  callback(value, attribute_name);
@@ -2686,7 +2811,7 @@ export function makeTable(options) {
2686
2811
  selected = value;
2687
2812
  });
2688
2813
  } else if (Array.isArray(select)) {
2689
- if (select.asArray) {
2814
+ if ((select as any).asArray) {
2690
2815
  selected = [];
2691
2816
  select.forEach((attribute, index) => {
2692
2817
  if (attribute === '*') select[index] = record;
@@ -2694,7 +2819,7 @@ export function makeTable(options) {
2694
2819
  });
2695
2820
  } else {
2696
2821
  selected = {};
2697
- const forceNulls = select.forceNulls;
2822
+ const forceNulls = (select as any).forceNulls;
2698
2823
  for (const attribute of select) {
2699
2824
  if (attribute === '*')
2700
2825
  for (const key in record) {
@@ -2718,12 +2843,13 @@ export function makeTable(options) {
2718
2843
  return transform;
2719
2844
  }
2720
2845
 
2846
+ // #section: pub-sub
2721
2847
  async subscribe(request: SubscriptionRequest): Promise<AsyncIterable<Record>> {
2722
2848
  if (!auditStore) throw new Error('Can not subscribe to a table without an audit log');
2723
2849
  if (!audit) {
2724
2850
  table({ table: tableName, database: databaseName, schemaDefined, attributes, audit: true });
2725
2851
  }
2726
- if (!request) request = {};
2852
+ if (!request) request = {} as any;
2727
2853
  const getFullRecord = !request.rawEvents;
2728
2854
  // While the count, !omitCurrent, and non-collection branches replay older messages, real-time
2729
2855
  // messages from the listener accumulate here and are drained at the end of the IIFE so they
@@ -2738,7 +2864,7 @@ export function makeTable(options) {
2738
2864
  const subscription = addSubscription(
2739
2865
  TableResource,
2740
2866
  thisId,
2741
- function (id: Id, auditRecord: any, localTime: number, beginTxn: boolean) {
2867
+ function (id: Id, auditRecord?: any, localTime?: any, beginTxn?: any) {
2742
2868
  if (dropDuringReplay) return;
2743
2869
  try {
2744
2870
  let type = auditRecord.type;
@@ -3037,13 +3163,13 @@ export function makeTable(options) {
3037
3163
  } else {
3038
3164
  let allowed = true;
3039
3165
  const context = this.getContext();
3040
- if (target.checkPermission) {
3166
+ if ((target as any)?.checkPermission) {
3041
3167
  // requesting authorization verification
3042
- allowed = this.allowCreate(context.user, message, context);
3168
+ allowed = this.allowDelete((context as any).user, target as any, context);
3043
3169
  }
3044
3170
  return when(allowed, (allowed: boolean) => {
3045
3171
  if (!allowed) {
3046
- throw new AccessViolation(context.user);
3172
+ throw new AccessViolation((context as any).user);
3047
3173
  }
3048
3174
  const id = requestTargetToId(target);
3049
3175
  this._writePublish(id, message, options);
@@ -3059,16 +3185,16 @@ export function makeTable(options) {
3059
3185
  key: id,
3060
3186
  store: primaryStore,
3061
3187
  entry: this.#entry,
3062
- nodeName: context?.nodeName,
3188
+ nodeName: (context as any)?.nodeName,
3063
3189
  validate: () => {
3064
- if (!context?.source) {
3190
+ if (!(context as any)?.source) {
3065
3191
  transaction.checkOverloaded();
3066
3192
  this.validate(message);
3067
3193
  }
3068
3194
  },
3069
3195
  before:
3070
- this.constructor.source?.publish && !context?.source
3071
- ? this.constructor.source.publish.bind(this.constructor.source, id, message, context)
3196
+ (this.constructor as any).source?.publish && !(context as any)?.source
3197
+ ? (this.constructor as any).source.publish.bind((this.constructor as any).source, id, message, context)
3072
3198
  : undefined,
3073
3199
  commit: (txnTime, existingEntry, _retry, transaction: any) => {
3074
3200
  // just need to update the version number of the record so it points to the latest audit record
@@ -3089,7 +3215,7 @@ export function makeTable(options) {
3089
3215
  0,
3090
3216
  true,
3091
3217
  {
3092
- user: context?.user,
3218
+ user: (context as any)?.user,
3093
3219
  residencyId: options?.residencyId,
3094
3220
  expiresAt: context?.expiresAt,
3095
3221
  nodeId: options?.nodeId,
@@ -3107,6 +3233,7 @@ export function makeTable(options) {
3107
3233
  write.beforeIntermediate = preCommitBlobsForRecordBefore(write, message, undefined, true);
3108
3234
  transaction.addWrite(write);
3109
3235
  }
3236
+ // #section: validation
3110
3237
  validate(record: any, patch?: boolean) {
3111
3238
  let validationErrors;
3112
3239
  const validateValue = (value, attribute: Attribute, name) => {
@@ -3276,6 +3403,7 @@ export function makeTable(options) {
3276
3403
  throw new ClientError(validationErrors.join('. '));
3277
3404
  }
3278
3405
  }
3406
+ // #section: stats-admin
3279
3407
  getUpdatedTime() {
3280
3408
  return this.#version;
3281
3409
  }
@@ -3294,7 +3422,7 @@ export function makeTable(options) {
3294
3422
  schemaDefined,
3295
3423
  attributes: new_attributes,
3296
3424
  });
3297
- return TableResource.indexingOperation;
3425
+ return (TableResource as any).indexingOperation;
3298
3426
  }
3299
3427
  static async removeAttributes(names: string[]) {
3300
3428
  const new_attributes = attributes.filter((attribute) => !names.includes(attribute.name));
@@ -3304,7 +3432,7 @@ export function makeTable(options) {
3304
3432
  schemaDefined,
3305
3433
  attributes: new_attributes,
3306
3434
  });
3307
- return TableResource.indexingOperation;
3435
+ return (TableResource as any).indexingOperation;
3308
3436
  }
3309
3437
  /**
3310
3438
  * Get the size of the table in bytes (based on amount of pages stored in the database)
@@ -3397,6 +3525,14 @@ export function makeTable(options) {
3397
3525
  * When attributes have been changed, we update the accessors that are assigned to this table
3398
3526
  */
3399
3527
  static updatedAttributes() {
3528
+ // Refresh on every call: schema reload mutates `attributes` in place, so the
3529
+ // class-construction snapshot would otherwise go stale.
3530
+ this.embedAttributes = (this.attributes as any[]).filter((a) => a?.embed);
3531
+ // Drop registry entries for attributes that are no longer `@embed`, so a dropped
3532
+ // directive doesn't leave a stale embedder or block a default refresh on re-add.
3533
+ const embedNames = new Set(this.embedAttributes.map((a) => a.name));
3534
+ for (const name of Object.keys(this.userEmbedders)) if (!embedNames.has(name)) delete this.userEmbedders[name];
3535
+ for (const name of this.userSetEmbedders) if (!embedNames.has(name)) this.userSetEmbedders.delete(name);
3400
3536
  propertyResolvers = this.propertyResolvers = {
3401
3537
  $id: (object, context, entry) => ({ value: entry.key }),
3402
3538
  $updatedtime: (object, context, entry) => entry.version,
@@ -3412,6 +3548,11 @@ export function makeTable(options) {
3412
3548
  attribute.resolve = null; // reset this
3413
3549
  const relationship = attribute.relationship;
3414
3550
  const computed = attribute.computed;
3551
+ // Register the default embedder unless an author override is set. Sits outside
3552
+ // the resolver chain below so `@embed` fields still flow through auto-HNSW indexing.
3553
+ if (attribute.embed && !TableResource.userSetEmbedders.has(attribute.name)) {
3554
+ this.userEmbedders[attribute.name] = createDefaultEmbedder(attribute.embed);
3555
+ }
3415
3556
  if (relationship) {
3416
3557
  if (attribute.indexed) {
3417
3558
  console.error(
@@ -3431,12 +3572,14 @@ export function makeTable(options) {
3431
3572
  const id = object[relationship.from ? relationship.from : primaryKey];
3432
3573
  const relatedTable = attribute.elements.definition.tableClass;
3433
3574
  if (returnEntry) {
3434
- return searchByIndex(
3435
- { attribute: relationship.to, value: id },
3436
- txnForContext(context).getReadTxn(),
3437
- false,
3438
- relatedTable,
3439
- false
3575
+ return (
3576
+ searchByIndex(
3577
+ { attribute: relationship.to, value: id },
3578
+ txnForContext(context).getReadTxn(),
3579
+ false,
3580
+ relatedTable,
3581
+ false
3582
+ ) as any
3440
3583
  ).map((entry) => {
3441
3584
  if (entry && entry.key !== undefined) return entry;
3442
3585
  return relatedTable.primaryStore.getEntry(entry, {
@@ -3517,6 +3660,15 @@ export function makeTable(options) {
3517
3660
  } else if (computed) {
3518
3661
  if (typeof computed.from === 'function') {
3519
3662
  this.setComputedAttribute(attribute.name, computed.from);
3663
+ } else if (attribute.computedFromExpression) {
3664
+ // build a fallback scope object with all attribute names set to undefined,
3665
+ // matching the behavior in graphql.ts to prevent ReferenceErrors
3666
+ const attributesFallback: { [key: string]: undefined } = {};
3667
+ for (const attr of this.attributes) attributesFallback[attr.name] = undefined;
3668
+ this.setComputedAttribute(
3669
+ attribute.name,
3670
+ createComputedFrom(attribute.computedFromExpression, attributesFallback)
3671
+ );
3520
3672
  }
3521
3673
  propertyResolvers[attribute.name] = attribute.resolve = (object, context, entry) => {
3522
3674
  const value = typeof computed.from === 'string' ? object[computed.from] : object;
@@ -3571,6 +3723,7 @@ export function makeTable(options) {
3571
3723
  }
3572
3724
  }
3573
3725
  }
3726
+ // #section: computed-history
3574
3727
  static setComputedAttribute(attribute_name, resolver) {
3575
3728
  const attribute = findAttribute(attributes, attribute_name);
3576
3729
  if (!attribute) {
@@ -3583,6 +3736,25 @@ export function makeTable(options) {
3583
3736
  }
3584
3737
  this.userResolvers[attribute_name] = resolver;
3585
3738
  }
3739
+ /**
3740
+ * Override the default embedder for an `@embed` attribute. Return the vector to
3741
+ * store at `attribute_name`. The embedder receives the write payload (the fields
3742
+ * present in the PUT/PATCH body), not the post-merge record, so multi-field
3743
+ * concatenation only works when all source fields are in the same write.
3744
+ */
3745
+ static setEmbedAttribute(attribute_name: string, embedder: Embedder): void {
3746
+ const attribute = findAttribute(attributes, attribute_name);
3747
+ if (!attribute) {
3748
+ console.error(`The attribute "${attribute_name}" does not exist in the table "${tableName}"`);
3749
+ return;
3750
+ }
3751
+ if (!attribute.embed) {
3752
+ console.error(`The attribute "${attribute_name}" is not declared with @embed in the table "${tableName}"`);
3753
+ return;
3754
+ }
3755
+ this.userEmbedders[attribute_name] = embedder;
3756
+ this.userSetEmbedders.add(attribute_name);
3757
+ }
3586
3758
  static async deleteHistory(endTime = 0, cleanupDeletedRecords = false) {
3587
3759
  let completion: Promise<void>;
3588
3760
  for (const auditRecord of auditStore.getRange({
@@ -3756,34 +3928,35 @@ export function makeTable(options) {
3756
3928
  function checkValidId(id) {
3757
3929
  switch (typeof id) {
3758
3930
  case 'number':
3931
+ if (isNaN(id)) throw new ClientError('Invalid primary key of NaN', 400);
3759
3932
  return true;
3760
3933
  case 'string':
3761
3934
  if (id.length < 659) return true; // max number of characters that can't expand our key size limit
3762
3935
  if (id.length > MAX_KEY_BYTES) {
3763
3936
  // we can quickly determine this is too big
3764
- throw new Error('Primary key size is too large: ' + id.length);
3937
+ throw new ClientError('Primary key size is too large: ' + id.length, 400);
3765
3938
  }
3766
3939
  // TODO: We could potentially have a faster test here, Buffer.byteLength is close, but we have to handle characters < 4 that are escaped in ordered-binary
3767
3940
  break; // otherwise we have to test it, in this range, unicode characters could put it over the limit
3768
3941
  case 'object':
3769
3942
  if (id === null) {
3770
- throw new Error('Invalid primary key of null');
3943
+ throw new ClientError('Invalid primary key of null', 400);
3771
3944
  }
3772
3945
  break; // otherwise we have to test it
3773
3946
  case 'bigint':
3774
3947
  if (id < 2n ** 64n && id > -(2n ** 64n)) return true;
3775
3948
  break; // otherwise we have to test it
3776
3949
  default:
3777
- throw new Error('Invalid primary key type: ' + typeof id);
3950
+ throw new ClientError('Invalid primary key type: ' + typeof id, 400);
3778
3951
  }
3779
3952
  // otherwise it is difficult to determine if the key size is too large
3780
3953
  // without actually attempting to serialize it
3781
3954
  const length = writeKey(id, TEST_WRITE_KEY_BUFFER, 0);
3782
- if (length > MAX_KEY_BYTES) throw new Error('Primary key size is too large: ' + id.length);
3955
+ if (length > MAX_KEY_BYTES) throw new ClientError('Primary key size is too large: ' + id.length, 400);
3783
3956
  return true;
3784
3957
  }
3785
3958
  function requestTargetToId(target: RequestTargetOrId): Id {
3786
- return typeof target === 'object' && target ? target.id : (target as Id);
3959
+ return typeof target === 'object' && target ? (target as any).id : (target as Id);
3787
3960
  }
3788
3961
  function isSearchTarget(target: RequestTargetOrId): target is RequestTarget {
3789
3962
  return typeof target === 'object' && target && (target as RequestTarget).isCollection;
@@ -3942,6 +4115,10 @@ export function makeTable(options) {
3942
4115
  }
3943
4116
 
3944
4117
  function ensureLoadedFromSource(source: typeof TableResource, id, entry, context, resource?, target?) {
4118
+ if (context?.onlyIfCached) {
4119
+ if (!entry?.value) throw new ServerError('Entry is not cached', 504);
4120
+ return;
4121
+ }
3945
4122
  if (hasSourceGet) {
3946
4123
  let needsSourceData = false;
3947
4124
  if (context.noCache) needsSourceData = true;
@@ -3970,10 +4147,9 @@ export function makeTable(options) {
3970
4147
  return entry;
3971
4148
  });
3972
4149
  // if the resource defines a method for indicating if stale-while-revalidate is allowed for a record
3973
- if (context?.onlyIfCached || (entry?.value && resource?.allowStaleWhileRevalidate?.(entry, id))) {
4150
+ if (entry?.value && resource?.allowStaleWhileRevalidate?.(entry, id)) {
3974
4151
  // since we aren't waiting for it any errors won't propagate so we should at least log them
3975
4152
  loadingFromSource.catch((error) => logger.warn?.(error));
3976
- if (context?.onlyIfCached && !resource.doesExist()) throw new ServerError('Entry is not cached', 504);
3977
4153
  return; // go ahead and return and let the current stale value be used while we re-validate
3978
4154
  } else return loadingFromSource; // return the promise for the resolved value
3979
4155
  }
@@ -3996,7 +4172,7 @@ export function makeTable(options) {
3996
4172
  if (transaction) {
3997
4173
  if (!transaction.db && isRocksDB) {
3998
4174
  // this is an uninitialized DatabaseTransaction, we can claim it
3999
- transaction.db = primaryStore;
4175
+ transaction.db = primaryStore as any;
4000
4176
  if (context?.timestamp) transaction.timestamp = context.timestamp;
4001
4177
  return transaction;
4002
4178
  }
@@ -4019,7 +4195,9 @@ export function makeTable(options) {
4019
4195
  transaction = nextTxn;
4020
4196
  } while (true);
4021
4197
  } else {
4022
- transaction = isRocksDB ? new ImmediateTransaction(primaryStore) : new ImmediateLMDBTransaction(primaryStore);
4198
+ transaction = (
4199
+ isRocksDB ? new ImmediateTransaction(primaryStore as any) : new ImmediateLMDBTransaction(primaryStore as any)
4200
+ ) as any;
4023
4201
  if (context) {
4024
4202
  context.transaction = transaction;
4025
4203
  if (context.timestamp) transaction.timestamp = context.timestamp;
@@ -4098,7 +4276,7 @@ export function makeTable(options) {
4098
4276
  return ids;
4099
4277
  }
4100
4278
 
4101
- function precedesExistingVersion(txnTime: number, existingEntry: Entry, nodeId?: number): number {
4279
+ function precedesExistingVersion(txnTime: number, existingEntry: Partial<Entry>, nodeId?: number): number {
4102
4280
  if (nodeId === undefined) {
4103
4281
  nodeId = getThisNodeId(auditStore);
4104
4282
  }
@@ -4200,7 +4378,7 @@ export function makeTable(options) {
4200
4378
  expiresAt: undefined,
4201
4379
  lastModified: undefined,
4202
4380
  };
4203
- const responseHeaders = context?.responseHeaders;
4381
+ const responseHeaders = (context as any)?.responseHeaders;
4204
4382
  return new Promise((resolve, reject) => {
4205
4383
  // we don't want to wait for the transaction because we want to return as fast as possible
4206
4384
  // and let the transaction commit in the background
@@ -4225,15 +4403,14 @@ export function makeTable(options) {
4225
4403
  if (typeof updatedRecord !== 'object') throw new Error('Only objects can be cached and stored in tables');
4226
4404
  if (updatedRecord.status > 0 && updatedRecord.headers) {
4227
4405
  // if the source has a status code and headers, treat it as a response
4228
- if (updatedRecord.status >= 300) {
4229
- if (updatedRecord.status === 304) {
4230
- // revalidation of our current cached record
4231
- updatedRecord = existingRecord;
4232
- version = existingVersion;
4233
- } else {
4234
- // if the source has an error status, we need to throw an error
4235
- throw new ServerError(updatedRecord.body || 'Error from source', updatedRecord.status);
4236
- } // there are definitely more status codes to handle
4406
+ const status = updatedRecord.status;
4407
+ if (status === 304) {
4408
+ // revalidation of our current cached record
4409
+ updatedRecord = existingRecord;
4410
+ version = existingVersion;
4411
+ } else if (!CACHEABLE_STATUS_CODES.has(status)) {
4412
+ // non-cacheable status - propagate to client without caching
4413
+ throw new ServerError(updatedRecord.body || 'Error from source', status);
4237
4414
  } else {
4238
4415
  let headers: any;
4239
4416
  const sourceHeaders = updatedRecord.headers;
@@ -4261,31 +4438,41 @@ export function makeTable(options) {
4261
4438
  if (data !== undefined) {
4262
4439
  // we have structured data that we have parsed
4263
4440
  delete headers['content-type']; // don't store the content type if we have already parsed it
4264
- updatedRecord = {
4265
- headers,
4266
- data,
4267
- };
4441
+ updatedRecord = { headers, data };
4268
4442
  } else {
4269
- updatedRecord = {
4270
- headers,
4271
- body: createBlob(updatedRecord.body),
4272
- };
4443
+ updatedRecord = { headers, body: createBlob(updatedRecord.body) };
4273
4444
  }
4445
+ if (status !== 200) updatedRecord.status = status;
4274
4446
  }
4275
4447
  }
4276
4448
  if (typeof updatedRecord.toJSON === 'function') updatedRecord = updatedRecord.toJSON();
4277
4449
  // updatedRecord may still be a frozen record (e.g. a reused existingRecord); copy-on-mutate
4278
- // before stamping the primary key below (records are immutable — 5.2 record caching relies
4279
- // on it — so we must not write through the frozen object).
4450
+ // before stamping the primary key and created/updated times below (records are immutable —
4451
+ // 5.2 record caching relies on it — so we must not write through the frozen object).
4280
4452
  if (isFrozenRecordObject(updatedRecord)) updatedRecord = { ...updatedRecord };
4281
4453
  if (primaryKey && updatedRecord[primaryKey] !== id) updatedRecord[primaryKey] = id;
4282
4454
  }
4283
4455
  resolved = true;
4284
- resolve({
4456
+ const resolvedEntry: Entry = {
4285
4457
  key: id,
4286
4458
  version,
4287
4459
  value: updatedRecord,
4288
- });
4460
+ expiresAt: sourceContext.expiresAt,
4461
+ metadataFlags: 0,
4462
+ size: 0,
4463
+ localTime: 0,
4464
+ nodeId: 0,
4465
+ residencyId: 0,
4466
+ } as any;
4467
+ // Give the plain object the RecordObject prototype so getExpiresAt/getUpdatedTime
4468
+ // are available on the immediately-resolved entry. We mutate the prototype
4469
+ // in-place rather than copying so that the commit callback (which adds
4470
+ // createdAt/updatedAt to updatedRecord) is still reflected in the entry value.
4471
+ if (updatedRecord && updatedRecord.constructor === Object) {
4472
+ Object.setPrototypeOf(updatedRecord, primaryStore.encoder.structPrototype);
4473
+ entryMap.set(updatedRecord, resolvedEntry);
4474
+ }
4475
+ resolve(resolvedEntry);
4289
4476
  } catch (error) {
4290
4477
  error.message += ` while resolving record ${id} for ${tableName}`;
4291
4478
  if (
@@ -4303,7 +4490,7 @@ export function makeTable(options) {
4303
4490
  key: id,
4304
4491
  version: existingVersion,
4305
4492
  value: existingRecord,
4306
- });
4493
+ } as any);
4307
4494
  logger.trace?.(error.message, '(returned stale record)');
4308
4495
  } else reject(error);
4309
4496
  const resolveDuration = performance.now() - start;
@@ -4400,7 +4587,7 @@ export function makeTable(options) {
4400
4587
  omitLocalRecord ? INVALIDATED : 0,
4401
4588
  (audit && (hasChanges || omitLocalRecord)) || null,
4402
4589
  {
4403
- user: sourceContext?.user,
4590
+ user: (sourceContext as any)?.user,
4404
4591
  expiresAt: sourceContext.expiresAt,
4405
4592
  residencyId,
4406
4593
  transaction,
@@ -4424,7 +4611,7 @@ export function makeTable(options) {
4424
4611
  txnTime,
4425
4612
  0,
4426
4613
  (audit && hasChanges) || null,
4427
- { user: sourceContext?.user, transaction, tableToTrack: tableName },
4614
+ { user: (sourceContext as any)?.user, transaction, tableToTrack: tableName },
4428
4615
  'delete',
4429
4616
  Boolean(invalidated)
4430
4617
  );
@@ -4434,6 +4621,19 @@ export function makeTable(options) {
4434
4621
  }
4435
4622
  },
4436
4623
  };
4624
+ // The cache-from-source write bypasses `_writeUpdate`, so wire the embed hook here
4625
+ // too (always the originating node). It runs after the client GET has resolved with
4626
+ // fresh source data, so it's a background commit: an embedder failure aborts the cache
4627
+ // write via the outer error handler (row re-embeds next read) and never reaches the
4628
+ // caller. Source-resolution errors are handled earlier, with the stale-data fallback.
4629
+ const embedBefore = buildEmbedBefore(
4630
+ updatedRecord,
4631
+ sourceContext,
4632
+ undefined,
4633
+ TableResource.embedAttributes,
4634
+ TableResource.userEmbedders
4635
+ );
4636
+ if (embedBefore) await embedBefore();
4437
4637
  sourceWrite.before = preCommitBlobsForRecordBefore(sourceWrite, updatedRecord);
4438
4638
  dbTxn.addWrite(sourceWrite);
4439
4639
  }),
@@ -4626,8 +4826,10 @@ export function makeTable(options) {
4626
4826
  if (shardOrResidencyList >= 65536) throw new Error(`Shard id ${shardOrResidencyList} must be below 65536`);
4627
4827
  const residencyList = server.shards?.get?.(shardOrResidencyList);
4628
4828
  if (residencyList) {
4629
- logger.trace?.(`Shard ${shardOrResidencyList} mapped to ${residencyList.map((node) => node.name).join(', ')}`);
4630
- return residencyList.map((node) => node.name);
4829
+ logger.trace?.(
4830
+ `Shard ${shardOrResidencyList} mapped to ${residencyList.map((node) => (node as any).name).join(', ')}`
4831
+ );
4832
+ return residencyList.map((node) => (node as any).name);
4631
4833
  }
4632
4834
  throw new Error(`Shard ${shardOrResidencyList} is not defined`);
4633
4835
  }
@@ -4651,9 +4853,9 @@ export function makeTable(options) {
4651
4853
  function preCommitBlobsForRecordBefore(
4652
4854
  write: any,
4653
4855
  record: any,
4654
- before?: () => Promise<void>,
4856
+ before?: () => Promise<void> | void,
4655
4857
  saveInRecord?: boolean
4656
- ): Promise<void> | void {
4858
+ ): any {
4657
4859
  const preCommit = startPreCommitBlobsForRecord(record, primaryStore.rootStore, saveInRecord);
4658
4860
  if (preCommit) {
4659
4861
  // track the blobs on the write so abort/skip paths can clean up the files if the commit doesn't reference them
@@ -4662,14 +4864,15 @@ export function makeTable(options) {
4662
4864
  // them to finish and we return a new callback for the before phase of the commit
4663
4865
  const callSources = before;
4664
4866
  return callSources
4665
- ? async () => {
4867
+ ? async (): Promise<any> => {
4666
4868
  // if we are calling the sources first and waiting for blobs, do those in order
4667
- await callSources();
4869
+ const result = callSources();
4870
+ if (result && (result as any).then) await result;
4668
4871
  await preCommit.complete();
4669
4872
  }
4670
4873
  : () => preCommit.complete();
4671
4874
  }
4672
- return before;
4875
+ return before as any;
4673
4876
  }
4674
4877
  }
4675
4878
 
@@ -4687,6 +4890,20 @@ function noop() {
4687
4890
  // prefetch callback
4688
4891
  }
4689
4892
 
4893
+ /**
4894
+ * Recreate a computed "from" function from a stored expression string. This is used when a table
4895
+ * is loaded from metadata on a thread that hasn't loaded the GraphQL schema, so the computed
4896
+ * function needs to be reconstructed from the persisted expression.
4897
+ */
4898
+ function createComputedFrom(computedFromExpression: string, attributesFallback?: any) {
4899
+ const script = new Script(
4900
+ attributesFallback
4901
+ ? `function computed(attributes) { return function(record) { with(attributes) { with (record) { return ${computedFromExpression}; } } } } computed;`
4902
+ : `function computed() { return function(record) { with (record) { return ${computedFromExpression}; } } } computed;`
4903
+ );
4904
+ return script.runInThisContext()(attributesFallback);
4905
+ }
4906
+
4690
4907
  const ENDS_WITH_TIMEZONE = /[+-][0-9]{2}:[0-9]{2}|[a-zA-Z]$/;
4691
4908
  /**
4692
4909
  * Coerce a string to the type defined by the attribute