@open-mercato/core 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2699.f8b50c8046

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 (414) hide show
  1. package/dist/modules/api_keys/data/entities.js +1 -1
  2. package/dist/modules/api_keys/data/entities.js.map +1 -1
  3. package/dist/modules/api_keys/services/apiKeyService.js +5 -5
  4. package/dist/modules/api_keys/services/apiKeyService.js.map +2 -2
  5. package/dist/modules/attachments/api/library/[id]/route.js +1 -1
  6. package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
  7. package/dist/modules/attachments/api/library/route.js +7 -9
  8. package/dist/modules/attachments/api/library/route.js.map +2 -2
  9. package/dist/modules/attachments/api/partitions/route.js +3 -3
  10. package/dist/modules/attachments/api/partitions/route.js.map +2 -2
  11. package/dist/modules/attachments/api/route.js +6 -5
  12. package/dist/modules/attachments/api/route.js.map +2 -2
  13. package/dist/modules/attachments/api/transfer/route.js +1 -1
  14. package/dist/modules/attachments/api/transfer/route.js.map +2 -2
  15. package/dist/modules/attachments/data/entities.js +2 -1
  16. package/dist/modules/attachments/data/entities.js.map +2 -2
  17. package/dist/modules/attachments/lib/ocrQueue.js +1 -1
  18. package/dist/modules/attachments/lib/ocrQueue.js.map +2 -2
  19. package/dist/modules/audit_logs/api/audit-logs/actions/export/route.js.map +2 -2
  20. package/dist/modules/audit_logs/api/audit-logs/actions/route.js.map +2 -2
  21. package/dist/modules/audit_logs/data/entities.js +1 -1
  22. package/dist/modules/audit_logs/data/entities.js.map +1 -1
  23. package/dist/modules/audit_logs/services/actionLogService.js +77 -70
  24. package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
  25. package/dist/modules/auth/api/roles/acl/route.js +1 -1
  26. package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
  27. package/dist/modules/auth/api/users/acl/route.js +2 -2
  28. package/dist/modules/auth/api/users/acl/route.js.map +2 -2
  29. package/dist/modules/auth/api/users/resend-invite/route.js +1 -1
  30. package/dist/modules/auth/api/users/resend-invite/route.js.map +2 -2
  31. package/dist/modules/auth/cli.js +12 -6
  32. package/dist/modules/auth/cli.js.map +2 -2
  33. package/dist/modules/auth/commands/users.js +1 -1
  34. package/dist/modules/auth/commands/users.js.map +2 -2
  35. package/dist/modules/auth/data/entities.js +1 -1
  36. package/dist/modules/auth/data/entities.js.map +2 -2
  37. package/dist/modules/auth/lib/setup-app.js +3 -3
  38. package/dist/modules/auth/lib/setup-app.js.map +2 -2
  39. package/dist/modules/auth/services/authService.js +2 -2
  40. package/dist/modules/auth/services/authService.js.map +2 -2
  41. package/dist/modules/business_rules/api/rules/route.js +3 -3
  42. package/dist/modules/business_rules/api/rules/route.js.map +2 -2
  43. package/dist/modules/business_rules/api/sets/[id]/members/route.js +7 -4
  44. package/dist/modules/business_rules/api/sets/[id]/members/route.js.map +2 -2
  45. package/dist/modules/business_rules/api/sets/route.js +3 -3
  46. package/dist/modules/business_rules/api/sets/route.js.map +2 -2
  47. package/dist/modules/business_rules/cli.js +1 -1
  48. package/dist/modules/business_rules/cli.js.map +2 -2
  49. package/dist/modules/business_rules/data/entities.js +2 -9
  50. package/dist/modules/business_rules/data/entities.js.map +2 -2
  51. package/dist/modules/business_rules/lib/rule-engine.js +1 -1
  52. package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
  53. package/dist/modules/catalog/api/option-schemas/route.js +0 -1
  54. package/dist/modules/catalog/api/option-schemas/route.js.map +2 -2
  55. package/dist/modules/catalog/data/entities.js +2 -11
  56. package/dist/modules/catalog/data/entities.js.map +2 -2
  57. package/dist/modules/configs/data/entities.js +2 -1
  58. package/dist/modules/configs/data/entities.js.map +2 -2
  59. package/dist/modules/currencies/commands/fetch-configs.js +3 -3
  60. package/dist/modules/currencies/commands/fetch-configs.js.map +2 -2
  61. package/dist/modules/currencies/data/entities.js +1 -1
  62. package/dist/modules/currencies/data/entities.js.map +2 -2
  63. package/dist/modules/customer_accounts/api/signup.js +1 -1
  64. package/dist/modules/customer_accounts/api/signup.js.map +2 -2
  65. package/dist/modules/customer_accounts/data/entities.js +1 -1
  66. package/dist/modules/customer_accounts/data/entities.js.map +2 -2
  67. package/dist/modules/customer_accounts/services/customerInvitationService.js +1 -1
  68. package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
  69. package/dist/modules/customer_accounts/services/customerSessionService.js +1 -1
  70. package/dist/modules/customer_accounts/services/customerSessionService.js.map +2 -2
  71. package/dist/modules/customer_accounts/services/customerTokenService.js +12 -7
  72. package/dist/modules/customer_accounts/services/customerTokenService.js.map +2 -2
  73. package/dist/modules/customers/api/interactions/conflicts/route.js +19 -17
  74. package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
  75. package/dist/modules/customers/api/interactions/counts/route.js +7 -6
  76. package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
  77. package/dist/modules/customers/api/interactions/route.js +28 -42
  78. package/dist/modules/customers/api/interactions/route.js.map +2 -2
  79. package/dist/modules/customers/api/utils.js +29 -24
  80. package/dist/modules/customers/api/utils.js.map +2 -2
  81. package/dist/modules/customers/cli.js +45 -40
  82. package/dist/modules/customers/cli.js.map +2 -2
  83. package/dist/modules/customers/commands/dictionaries.js +1 -1
  84. package/dist/modules/customers/commands/dictionaries.js.map +2 -2
  85. package/dist/modules/customers/commands/tags.js +1 -1
  86. package/dist/modules/customers/commands/tags.js.map +2 -2
  87. package/dist/modules/customers/data/entities.js +2 -12
  88. package/dist/modules/customers/data/entities.js.map +2 -2
  89. package/dist/modules/customers/lib/interactionProjection.js +18 -15
  90. package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
  91. package/dist/modules/customers/lib/personCompanyLinkTable.js +6 -8
  92. package/dist/modules/customers/lib/personCompanyLinkTable.js.map +2 -2
  93. package/dist/modules/dashboards/api/roles/widgets/route.js +1 -1
  94. package/dist/modules/dashboards/api/roles/widgets/route.js.map +2 -2
  95. package/dist/modules/dashboards/api/users/widgets/route.js +1 -1
  96. package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
  97. package/dist/modules/dashboards/data/entities.js +1 -1
  98. package/dist/modules/dashboards/data/entities.js.map +1 -1
  99. package/dist/modules/data_sync/api/mappings/route.js +1 -1
  100. package/dist/modules/data_sync/api/mappings/route.js.map +2 -2
  101. package/dist/modules/data_sync/data/entities.js +2 -1
  102. package/dist/modules/data_sync/data/entities.js.map +2 -2
  103. package/dist/modules/data_sync/lib/id-mapping.js +1 -1
  104. package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
  105. package/dist/modules/data_sync/lib/sync-run-service.js +1 -1
  106. package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
  107. package/dist/modules/dictionaries/commands/factory.js +1 -1
  108. package/dist/modules/dictionaries/commands/factory.js.map +2 -2
  109. package/dist/modules/dictionaries/data/entities.js +2 -9
  110. package/dist/modules/dictionaries/data/entities.js.map +2 -2
  111. package/dist/modules/directory/commands/organizations.js +4 -4
  112. package/dist/modules/directory/commands/organizations.js.map +2 -2
  113. package/dist/modules/directory/data/entities.js +2 -1
  114. package/dist/modules/directory/data/entities.js.map +2 -2
  115. package/dist/modules/entities/api/definitions.js +2 -2
  116. package/dist/modules/entities/api/definitions.js.map +2 -2
  117. package/dist/modules/entities/api/encryption.js +2 -2
  118. package/dist/modules/entities/api/encryption.js.map +2 -2
  119. package/dist/modules/entities/api/relations/options.js +2 -2
  120. package/dist/modules/entities/api/relations/options.js.map +2 -2
  121. package/dist/modules/entities/cli.js +4 -4
  122. package/dist/modules/entities/cli.js.map +2 -2
  123. package/dist/modules/entities/data/entities.js +1 -1
  124. package/dist/modules/entities/data/entities.js.map +2 -2
  125. package/dist/modules/entities/lib/field-definitions.js +2 -2
  126. package/dist/modules/entities/lib/field-definitions.js.map +2 -2
  127. package/dist/modules/entities/lib/register.js +1 -1
  128. package/dist/modules/entities/lib/register.js.map +2 -2
  129. package/dist/modules/feature_toggles/data/entities.js +2 -9
  130. package/dist/modules/feature_toggles/data/entities.js.map +2 -2
  131. package/dist/modules/inbox_ops/api/proposals/counts/route.js +3 -6
  132. package/dist/modules/inbox_ops/api/proposals/counts/route.js.map +2 -2
  133. package/dist/modules/inbox_ops/data/entities.js +2 -8
  134. package/dist/modules/inbox_ops/data/entities.js.map +2 -2
  135. package/dist/modules/inbox_ops/lib/messagesIntegration.js +6 -6
  136. package/dist/modules/inbox_ops/lib/messagesIntegration.js.map +2 -2
  137. package/dist/modules/integrations/data/entities.js +2 -1
  138. package/dist/modules/integrations/data/entities.js.map +2 -2
  139. package/dist/modules/integrations/lib/credentials-service.js +1 -1
  140. package/dist/modules/integrations/lib/credentials-service.js.map +2 -2
  141. package/dist/modules/integrations/lib/log-service.js +1 -1
  142. package/dist/modules/integrations/lib/log-service.js.map +2 -2
  143. package/dist/modules/integrations/lib/state-service.js +1 -1
  144. package/dist/modules/integrations/lib/state-service.js.map +2 -2
  145. package/dist/modules/messages/api/route.js +90 -93
  146. package/dist/modules/messages/api/route.js.map +2 -2
  147. package/dist/modules/messages/api/unread-count/route.js +8 -7
  148. package/dist/modules/messages/api/unread-count/route.js.map +2 -2
  149. package/dist/modules/messages/commands/confirmations.js +1 -1
  150. package/dist/modules/messages/commands/confirmations.js.map +2 -2
  151. package/dist/modules/messages/commands/messages.js +3 -3
  152. package/dist/modules/messages/commands/messages.js.map +2 -2
  153. package/dist/modules/messages/data/entities.js +2 -1
  154. package/dist/modules/messages/data/entities.js.map +2 -2
  155. package/dist/modules/messages/lib/email-sender.js +1 -1
  156. package/dist/modules/messages/lib/email-sender.js.map +2 -2
  157. package/dist/modules/messages/lib/searchLookup.js +8 -8
  158. package/dist/modules/messages/lib/searchLookup.js.map +2 -2
  159. package/dist/modules/messages/lib/tokenConsumption.js +9 -4
  160. package/dist/modules/messages/lib/tokenConsumption.js.map +2 -2
  161. package/dist/modules/notifications/data/entities.js +2 -1
  162. package/dist/modules/notifications/data/entities.js.map +2 -2
  163. package/dist/modules/notifications/lib/notificationRecipients.js +15 -5
  164. package/dist/modules/notifications/lib/notificationRecipients.js.map +2 -2
  165. package/dist/modules/notifications/lib/notificationService.js +39 -34
  166. package/dist/modules/notifications/lib/notificationService.js.map +2 -2
  167. package/dist/modules/notifications/workers/create-notification.worker.js +14 -13
  168. package/dist/modules/notifications/workers/create-notification.worker.js.map +2 -2
  169. package/dist/modules/payment_gateways/api/transactions/route.js +2 -2
  170. package/dist/modules/payment_gateways/api/transactions/route.js.map +2 -2
  171. package/dist/modules/payment_gateways/data/entities.js +2 -1
  172. package/dist/modules/payment_gateways/data/entities.js.map +2 -2
  173. package/dist/modules/payment_gateways/lib/gateway-service.js +1 -1
  174. package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
  175. package/dist/modules/payment_gateways/lib/webhook-utils.js +2 -2
  176. package/dist/modules/payment_gateways/lib/webhook-utils.js.map +2 -2
  177. package/dist/modules/perspectives/data/entities.js +1 -1
  178. package/dist/modules/perspectives/data/entities.js.map +2 -2
  179. package/dist/modules/planner/data/entities.js +1 -1
  180. package/dist/modules/planner/data/entities.js.map +2 -2
  181. package/dist/modules/progress/data/entities.js +2 -1
  182. package/dist/modules/progress/data/entities.js.map +2 -2
  183. package/dist/modules/progress/lib/progressServiceImpl.js +1 -1
  184. package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
  185. package/dist/modules/query_index/api/status.js +66 -57
  186. package/dist/modules/query_index/api/status.js.map +2 -2
  187. package/dist/modules/query_index/cli.js +39 -24
  188. package/dist/modules/query_index/cli.js.map +2 -2
  189. package/dist/modules/query_index/data/entities.js +1 -1
  190. package/dist/modules/query_index/data/entities.js.map +2 -2
  191. package/dist/modules/query_index/di.js +25 -13
  192. package/dist/modules/query_index/di.js.map +2 -2
  193. package/dist/modules/query_index/lib/batch.js +31 -33
  194. package/dist/modules/query_index/lib/batch.js.map +2 -2
  195. package/dist/modules/query_index/lib/coverage.js +63 -50
  196. package/dist/modules/query_index/lib/coverage.js.map +2 -2
  197. package/dist/modules/query_index/lib/engine.js +592 -588
  198. package/dist/modules/query_index/lib/engine.js.map +2 -2
  199. package/dist/modules/query_index/lib/indexer.js +74 -47
  200. package/dist/modules/query_index/lib/indexer.js.map +2 -2
  201. package/dist/modules/query_index/lib/jobs.js +37 -24
  202. package/dist/modules/query_index/lib/jobs.js.map +2 -2
  203. package/dist/modules/query_index/lib/purge.js +19 -11
  204. package/dist/modules/query_index/lib/purge.js.map +2 -2
  205. package/dist/modules/query_index/lib/reindexer.js +47 -44
  206. package/dist/modules/query_index/lib/reindexer.js.map +2 -2
  207. package/dist/modules/query_index/lib/search-tokens.js +47 -25
  208. package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
  209. package/dist/modules/query_index/lib/stale.js +14 -12
  210. package/dist/modules/query_index/lib/stale.js.map +2 -2
  211. package/dist/modules/query_index/lib/subscriber-scope.js +2 -2
  212. package/dist/modules/query_index/lib/subscriber-scope.js.map +2 -2
  213. package/dist/modules/query_index/subscribers/delete_one.js +3 -2
  214. package/dist/modules/query_index/subscribers/delete_one.js.map +2 -2
  215. package/dist/modules/resources/commands/tag-assignments.js +1 -1
  216. package/dist/modules/resources/commands/tag-assignments.js.map +2 -2
  217. package/dist/modules/resources/commands/tags.js +1 -1
  218. package/dist/modules/resources/commands/tags.js.map +2 -2
  219. package/dist/modules/resources/data/entities.js +2 -1
  220. package/dist/modules/resources/data/entities.js.map +2 -2
  221. package/dist/modules/sales/commands/documentAddresses.js +2 -2
  222. package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
  223. package/dist/modules/sales/commands/notes.js.map +2 -2
  224. package/dist/modules/sales/commands/tags.js +1 -1
  225. package/dist/modules/sales/commands/tags.js.map +2 -2
  226. package/dist/modules/sales/data/enrichers.js +9 -8
  227. package/dist/modules/sales/data/enrichers.js.map +2 -2
  228. package/dist/modules/sales/data/entities.js +2 -11
  229. package/dist/modules/sales/data/entities.js.map +2 -2
  230. package/dist/modules/shipping_carriers/data/entities.js +2 -1
  231. package/dist/modules/shipping_carriers/data/entities.js.map +2 -2
  232. package/dist/modules/shipping_carriers/lib/shipping-service.js +1 -1
  233. package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
  234. package/dist/modules/shipping_carriers/lib/webhook-utils.js +2 -2
  235. package/dist/modules/shipping_carriers/lib/webhook-utils.js.map +2 -2
  236. package/dist/modules/staff/data/entities.js +1 -1
  237. package/dist/modules/staff/data/entities.js.map +2 -2
  238. package/dist/modules/translations/api/[entityType]/[entityId]/route.js +3 -5
  239. package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
  240. package/dist/modules/translations/api/context.js +2 -2
  241. package/dist/modules/translations/api/context.js.map +2 -2
  242. package/dist/modules/translations/commands/translations.js +46 -39
  243. package/dist/modules/translations/commands/translations.js.map +2 -2
  244. package/dist/modules/translations/components/TranslationManager.js +19 -10
  245. package/dist/modules/translations/components/TranslationManager.js.map +2 -2
  246. package/dist/modules/translations/data/entities.js +1 -1
  247. package/dist/modules/translations/data/entities.js.map +2 -2
  248. package/dist/modules/translations/lib/apply.js +4 -4
  249. package/dist/modules/translations/lib/apply.js.map +2 -2
  250. package/dist/modules/translations/lib/batch.js +3 -2
  251. package/dist/modules/translations/lib/batch.js.map +2 -2
  252. package/dist/modules/translations/subscribers/cleanup.js +3 -5
  253. package/dist/modules/translations/subscribers/cleanup.js.map +2 -2
  254. package/dist/modules/workflows/api/definitions/route.js +1 -1
  255. package/dist/modules/workflows/api/definitions/route.js.map +2 -2
  256. package/dist/modules/workflows/cli.js +5 -5
  257. package/dist/modules/workflows/cli.js.map +2 -2
  258. package/dist/modules/workflows/data/entities.js +2 -1
  259. package/dist/modules/workflows/data/entities.js.map +2 -2
  260. package/dist/modules/workflows/lib/event-logger.js +2 -2
  261. package/dist/modules/workflows/lib/event-logger.js.map +2 -2
  262. package/dist/modules/workflows/lib/seeds.js +16 -1
  263. package/dist/modules/workflows/lib/seeds.js.map +2 -2
  264. package/dist/modules/workflows/lib/step-handler.js +3 -3
  265. package/dist/modules/workflows/lib/step-handler.js.map +2 -2
  266. package/dist/modules/workflows/lib/task-handler.js +1 -1
  267. package/dist/modules/workflows/lib/task-handler.js.map +2 -2
  268. package/dist/modules/workflows/lib/transition-handler.js +1 -1
  269. package/dist/modules/workflows/lib/transition-handler.js.map +2 -2
  270. package/dist/modules/workflows/lib/workflow-executor.js +2 -2
  271. package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
  272. package/jest.config.cjs +4 -2
  273. package/package.json +3 -3
  274. package/src/modules/api_keys/data/entities.ts +1 -1
  275. package/src/modules/api_keys/services/apiKeyService.ts +5 -5
  276. package/src/modules/attachments/api/library/[id]/route.ts +1 -1
  277. package/src/modules/attachments/api/library/route.ts +10 -12
  278. package/src/modules/attachments/api/partitions/route.ts +3 -3
  279. package/src/modules/attachments/api/route.ts +10 -8
  280. package/src/modules/attachments/api/transfer/route.ts +1 -1
  281. package/src/modules/attachments/data/entities.ts +2 -1
  282. package/src/modules/attachments/lib/ocrQueue.ts +1 -1
  283. package/src/modules/audit_logs/api/audit-logs/actions/export/route.ts +4 -4
  284. package/src/modules/audit_logs/api/audit-logs/actions/route.ts +4 -4
  285. package/src/modules/audit_logs/data/entities.ts +1 -1
  286. package/src/modules/audit_logs/services/actionLogService.ts +96 -87
  287. package/src/modules/auth/api/roles/acl/route.ts +1 -1
  288. package/src/modules/auth/api/users/acl/route.ts +2 -2
  289. package/src/modules/auth/api/users/resend-invite/route.ts +1 -1
  290. package/src/modules/auth/cli.ts +46 -40
  291. package/src/modules/auth/commands/users.ts +1 -1
  292. package/src/modules/auth/data/entities.ts +1 -1
  293. package/src/modules/auth/lib/setup-app.ts +3 -3
  294. package/src/modules/auth/services/authService.ts +2 -2
  295. package/src/modules/business_rules/api/rules/route.ts +3 -3
  296. package/src/modules/business_rules/api/sets/[id]/members/route.ts +7 -4
  297. package/src/modules/business_rules/api/sets/route.ts +3 -3
  298. package/src/modules/business_rules/cli.ts +1 -1
  299. package/src/modules/business_rules/data/entities.ts +2 -9
  300. package/src/modules/business_rules/lib/rule-engine.ts +1 -1
  301. package/src/modules/catalog/api/option-schemas/route.ts +0 -1
  302. package/src/modules/catalog/data/entities.ts +2 -11
  303. package/src/modules/configs/data/entities.ts +2 -1
  304. package/src/modules/currencies/commands/fetch-configs.ts +3 -3
  305. package/src/modules/currencies/data/entities.ts +1 -1
  306. package/src/modules/customer_accounts/api/signup.ts +1 -1
  307. package/src/modules/customer_accounts/data/entities.ts +1 -1
  308. package/src/modules/customer_accounts/services/customerInvitationService.ts +1 -1
  309. package/src/modules/customer_accounts/services/customerSessionService.ts +1 -1
  310. package/src/modules/customer_accounts/services/customerTokenService.ts +26 -15
  311. package/src/modules/customers/api/interactions/conflicts/route.ts +26 -23
  312. package/src/modules/customers/api/interactions/counts/route.ts +13 -11
  313. package/src/modules/customers/api/interactions/route.ts +32 -44
  314. package/src/modules/customers/api/utils.ts +45 -37
  315. package/src/modules/customers/cli.ts +88 -67
  316. package/src/modules/customers/commands/dictionaries.ts +1 -1
  317. package/src/modules/customers/commands/tags.ts +1 -1
  318. package/src/modules/customers/data/entities.ts +2 -12
  319. package/src/modules/customers/lib/interactionProjection.ts +36 -25
  320. package/src/modules/customers/lib/personCompanyLinkTable.ts +13 -18
  321. package/src/modules/dashboards/api/roles/widgets/route.ts +1 -1
  322. package/src/modules/dashboards/api/users/widgets/route.ts +1 -1
  323. package/src/modules/dashboards/data/entities.ts +1 -1
  324. package/src/modules/data_sync/api/mappings/route.ts +1 -1
  325. package/src/modules/data_sync/data/entities.ts +2 -1
  326. package/src/modules/data_sync/lib/id-mapping.ts +1 -1
  327. package/src/modules/data_sync/lib/sync-run-service.ts +1 -1
  328. package/src/modules/dictionaries/commands/factory.ts +1 -1
  329. package/src/modules/dictionaries/data/entities.ts +2 -9
  330. package/src/modules/directory/commands/organizations.ts +4 -4
  331. package/src/modules/directory/data/entities.ts +2 -1
  332. package/src/modules/entities/api/definitions.ts +2 -2
  333. package/src/modules/entities/api/encryption.ts +2 -2
  334. package/src/modules/entities/api/relations/options.ts +8 -3
  335. package/src/modules/entities/cli.ts +4 -4
  336. package/src/modules/entities/data/entities.ts +1 -1
  337. package/src/modules/entities/lib/field-definitions.ts +2 -2
  338. package/src/modules/entities/lib/register.ts +1 -1
  339. package/src/modules/feature_toggles/data/entities.ts +2 -9
  340. package/src/modules/inbox_ops/api/proposals/counts/route.ts +10 -10
  341. package/src/modules/inbox_ops/data/entities.ts +2 -8
  342. package/src/modules/inbox_ops/lib/messagesIntegration.ts +12 -11
  343. package/src/modules/integrations/data/entities.ts +2 -1
  344. package/src/modules/integrations/lib/credentials-service.ts +1 -1
  345. package/src/modules/integrations/lib/log-service.ts +1 -1
  346. package/src/modules/integrations/lib/state-service.ts +1 -1
  347. package/src/modules/messages/api/route.ts +134 -123
  348. package/src/modules/messages/api/unread-count/route.ts +19 -16
  349. package/src/modules/messages/commands/confirmations.ts +1 -1
  350. package/src/modules/messages/commands/messages.ts +3 -3
  351. package/src/modules/messages/data/entities.ts +2 -1
  352. package/src/modules/messages/lib/email-sender.ts +1 -1
  353. package/src/modules/messages/lib/searchLookup.ts +16 -13
  354. package/src/modules/messages/lib/tokenConsumption.ts +16 -8
  355. package/src/modules/notifications/data/entities.ts +2 -1
  356. package/src/modules/notifications/lib/notificationRecipients.ts +42 -26
  357. package/src/modules/notifications/lib/notificationService.ts +53 -42
  358. package/src/modules/notifications/workers/create-notification.worker.ts +20 -17
  359. package/src/modules/payment_gateways/api/transactions/route.ts +2 -2
  360. package/src/modules/payment_gateways/data/entities.ts +2 -1
  361. package/src/modules/payment_gateways/lib/gateway-service.ts +1 -1
  362. package/src/modules/payment_gateways/lib/webhook-utils.ts +2 -2
  363. package/src/modules/perspectives/data/entities.ts +1 -1
  364. package/src/modules/planner/data/entities.ts +1 -1
  365. package/src/modules/progress/data/entities.ts +2 -1
  366. package/src/modules/progress/lib/progressServiceImpl.ts +1 -1
  367. package/src/modules/query_index/api/status.ts +85 -71
  368. package/src/modules/query_index/cli.ts +51 -31
  369. package/src/modules/query_index/data/entities.ts +1 -1
  370. package/src/modules/query_index/di.ts +41 -16
  371. package/src/modules/query_index/lib/batch.ts +68 -55
  372. package/src/modules/query_index/lib/coverage.ts +115 -88
  373. package/src/modules/query_index/lib/engine.ts +1036 -1096
  374. package/src/modules/query_index/lib/indexer.ts +115 -79
  375. package/src/modules/query_index/lib/jobs.ts +51 -31
  376. package/src/modules/query_index/lib/purge.ts +25 -19
  377. package/src/modules/query_index/lib/reindexer.ts +97 -84
  378. package/src/modules/query_index/lib/search-tokens.ts +67 -36
  379. package/src/modules/query_index/lib/stale.ts +14 -17
  380. package/src/modules/query_index/lib/subscriber-scope.ts +6 -5
  381. package/src/modules/query_index/subscribers/delete_one.ts +9 -6
  382. package/src/modules/resources/commands/tag-assignments.ts +1 -1
  383. package/src/modules/resources/commands/tags.ts +1 -1
  384. package/src/modules/resources/data/entities.ts +2 -1
  385. package/src/modules/sales/commands/documentAddresses.ts +2 -2
  386. package/src/modules/sales/commands/notes.ts +1 -1
  387. package/src/modules/sales/commands/tags.ts +1 -1
  388. package/src/modules/sales/data/enrichers.ts +17 -13
  389. package/src/modules/sales/data/entities.ts +2 -11
  390. package/src/modules/shipping_carriers/data/entities.ts +2 -1
  391. package/src/modules/shipping_carriers/lib/shipping-service.ts +1 -1
  392. package/src/modules/shipping_carriers/lib/webhook-utils.ts +2 -2
  393. package/src/modules/staff/data/entities.ts +1 -1
  394. package/src/modules/translations/api/[entityType]/[entityId]/route.ts +14 -11
  395. package/src/modules/translations/api/context.ts +4 -4
  396. package/src/modules/translations/commands/translations.ts +116 -81
  397. package/src/modules/translations/components/TranslationManager.tsx +23 -14
  398. package/src/modules/translations/data/entities.ts +1 -1
  399. package/src/modules/translations/i18n/de.json +1 -0
  400. package/src/modules/translations/i18n/en.json +1 -0
  401. package/src/modules/translations/i18n/es.json +1 -0
  402. package/src/modules/translations/i18n/pl.json +1 -0
  403. package/src/modules/translations/lib/apply.ts +6 -6
  404. package/src/modules/translations/lib/batch.ts +9 -7
  405. package/src/modules/translations/subscribers/cleanup.ts +10 -11
  406. package/src/modules/workflows/api/definitions/route.ts +1 -1
  407. package/src/modules/workflows/cli.ts +5 -5
  408. package/src/modules/workflows/data/entities.ts +2 -1
  409. package/src/modules/workflows/lib/event-logger.ts +2 -2
  410. package/src/modules/workflows/lib/seeds.ts +16 -1
  411. package/src/modules/workflows/lib/step-handler.ts +3 -3
  412. package/src/modules/workflows/lib/task-handler.ts +1 -1
  413. package/src/modules/workflows/lib/transition-handler.ts +1 -1
  414. package/src/modules/workflows/lib/workflow-executor.ts +2 -2
@@ -1,4 +1,4 @@
1
- import type { Knex } from 'knex'
1
+ import { type Kysely, sql } from 'kysely'
2
2
  import { buildIndexDocument, type IndexCustomFieldValue } from './document'
3
3
  import { replaceSearchTokensForBatch, isSearchDebugEnabled } from './search-tokens'
4
4
 
@@ -45,7 +45,7 @@ function normalizeScopedValue(value: unknown): string | null {
45
45
  }
46
46
 
47
47
  export async function upsertIndexBatch(
48
- knex: Knex,
48
+ db: Kysely<any>,
49
49
  entityType: string,
50
50
  rows: AnyRow[],
51
51
  scope: ScopeOverrides,
@@ -68,25 +68,31 @@ export async function upsertIndexBatch(
68
68
  ),
69
69
  )
70
70
  if (entityIds.length) {
71
- const entityRows = await knex<AnyRow>('customer_entities').whereIn('id', entityIds)
71
+ const entityRows = await db
72
+ .selectFrom('customer_entities' as any)
73
+ .selectAll()
74
+ .where('id' as any, 'in', entityIds)
75
+ .execute() as AnyRow[]
72
76
  customerEntitiesById = new Map(entityRows.map((row) => [normalizeId(row.id), row]))
73
77
  }
74
78
  }
75
79
 
76
- const customFieldRows = await knex<CustomFieldRow>('custom_field_values')
80
+ const customFieldRows = await db
81
+ .selectFrom('custom_field_values' as any)
77
82
  .select([
78
- 'record_id',
79
- 'field_key',
80
- 'value_text',
81
- 'value_multiline',
82
- 'value_int',
83
- 'value_float',
84
- 'value_bool',
85
- 'organization_id',
86
- 'tenant_id',
83
+ 'record_id' as any,
84
+ 'field_key' as any,
85
+ 'value_text' as any,
86
+ 'value_multiline' as any,
87
+ 'value_int' as any,
88
+ 'value_float' as any,
89
+ 'value_bool' as any,
90
+ 'organization_id' as any,
91
+ 'tenant_id' as any,
87
92
  ])
88
- .where('entity_id', entityType)
89
- .whereIn('record_id', recordIds)
93
+ .where('entity_id' as any, '=', entityType)
94
+ .where('record_id' as any, 'in', recordIds)
95
+ .execute() as CustomFieldRow[]
90
96
 
91
97
  const customFieldMap = new Map<string, CustomFieldRow[]>()
92
98
  for (const fieldRow of customFieldRows) {
@@ -207,10 +213,10 @@ export async function upsertIndexBatch(
207
213
  entity_id: payload.entity_id,
208
214
  organization_id: payload.organization_id,
209
215
  tenant_id: payload.tenant_id,
210
- doc: payload.doc,
216
+ doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
211
217
  index_version: payload.index_version,
212
- created_at: knex.fn.now(),
213
- updated_at: knex.fn.now(),
218
+ created_at: sql`now()`,
219
+ updated_at: sql`now()`,
214
220
  deleted_at: null,
215
221
  }))
216
222
 
@@ -223,19 +229,22 @@ export async function upsertIndexBatch(
223
229
  }))
224
230
 
225
231
  try {
226
- await knex('entity_indexes')
227
- .insert(insertRows)
228
- .onConflict(['entity_type', 'entity_id', 'organization_id_coalesced'])
229
- .merge({
230
- doc: knex.raw('excluded.doc'),
231
- index_version: knex.raw('excluded.index_version'),
232
- organization_id: knex.raw('excluded.organization_id'),
233
- tenant_id: knex.raw('excluded.tenant_id'),
234
- deleted_at: knex.raw('excluded.deleted_at'),
235
- updated_at: knex.fn.now(),
236
- })
232
+ await db
233
+ .insertInto('entity_indexes' as any)
234
+ .values(insertRows as any)
235
+ .onConflict((oc: any) => oc
236
+ .columns(['entity_type', 'entity_id', 'organization_id_coalesced'])
237
+ .doUpdateSet({
238
+ doc: sql`excluded.doc`,
239
+ index_version: sql`excluded.index_version`,
240
+ organization_id: sql`excluded.organization_id`,
241
+ tenant_id: sql`excluded.tenant_id`,
242
+ deleted_at: sql`excluded.deleted_at`,
243
+ updated_at: sql`now()`,
244
+ } as any))
245
+ .execute()
237
246
  try {
238
- await replaceSearchTokensForBatch(knex, tokenPayloads)
247
+ await replaceSearchTokensForBatch(db, tokenPayloads)
239
248
  } catch {}
240
249
  if (debugEnabled) {
241
250
  console.info('[reindex:batch:tokens]', {
@@ -247,36 +256,40 @@ export async function upsertIndexBatch(
247
256
  }
248
257
  return
249
258
  } catch {
250
- await knex.transaction(async (trx) => {
251
- const now = trx.fn.now()
259
+ await db.transaction().execute(async (trx) => {
252
260
  for (const payload of basePayloads) {
253
- const updated = await trx('entity_indexes')
254
- .where({
255
- entity_type: payload.entity_type,
256
- entity_id: payload.entity_id,
257
- organization_id: payload.organization_id ?? null,
258
- })
259
- .update({
260
- doc: payload.doc,
261
+ let updateQuery = trx
262
+ .updateTable('entity_indexes' as any)
263
+ .set({
264
+ doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
261
265
  index_version: payload.index_version,
262
266
  organization_id: payload.organization_id ?? null,
263
267
  tenant_id: payload.tenant_id ?? null,
264
- updated_at: now,
268
+ updated_at: sql`now()`,
265
269
  deleted_at: null,
266
- })
267
- if (updated) continue
270
+ } as any)
271
+ .where('entity_type' as any, '=', payload.entity_type)
272
+ .where('entity_id' as any, '=', payload.entity_id)
273
+ updateQuery = payload.organization_id == null
274
+ ? updateQuery.where('organization_id' as any, 'is', null as any)
275
+ : updateQuery.where('organization_id' as any, '=', payload.organization_id)
276
+ const result = await updateQuery.executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
277
+ if (result && Number(result.numUpdatedRows ?? 0) > 0) continue
268
278
  try {
269
- await trx('entity_indexes').insert({
270
- entity_type: payload.entity_type,
271
- entity_id: payload.entity_id,
272
- organization_id: payload.organization_id,
273
- tenant_id: payload.tenant_id,
274
- doc: payload.doc,
275
- index_version: payload.index_version,
276
- created_at: now,
277
- updated_at: now,
278
- deleted_at: null,
279
- })
279
+ await trx
280
+ .insertInto('entity_indexes' as any)
281
+ .values({
282
+ entity_type: payload.entity_type,
283
+ entity_id: payload.entity_id,
284
+ organization_id: payload.organization_id,
285
+ tenant_id: payload.tenant_id,
286
+ doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
287
+ index_version: payload.index_version,
288
+ created_at: sql`now()`,
289
+ updated_at: sql`now()`,
290
+ deleted_at: null,
291
+ } as any)
292
+ .execute()
280
293
  } catch {
281
294
  // ignore duplicate insert race; another concurrent worker updated the row
282
295
  }
@@ -284,6 +297,6 @@ export async function upsertIndexBatch(
284
297
  })
285
298
  }
286
299
  try {
287
- await replaceSearchTokensForBatch(knex, tokenPayloads)
300
+ await replaceSearchTokensForBatch(db, tokenPayloads)
288
301
  } catch {}
289
302
  }
@@ -1,5 +1,5 @@
1
1
  import type { EntityManager } from '@mikro-orm/postgresql'
2
- import type { Knex } from 'knex'
2
+ import { type Kysely, sql } from 'kysely'
3
3
  import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
4
4
 
5
5
  export type CoverageScope = {
@@ -57,71 +57,86 @@ function normalizeOrganizationForStore(orgId: string | null | undefined): string
57
57
  return orgId ?? GLOBAL_ORGANIZATION_PLACEHOLDER
58
58
  }
59
59
 
60
- function applyOrganizationCondition(
61
- qb: Knex.QueryBuilder<any, any>,
60
+ function applyOrganizationCondition<QB extends { where: (...args: any[]) => QB }>(
61
+ qb: QB,
62
62
  column: string,
63
- organizationId: string | null | undefined
64
- ) {
63
+ organizationId: string | null | undefined,
64
+ ): QB {
65
65
  const stored = normalizeOrganizationForStore(organizationId ?? null)
66
66
  if (stored === GLOBAL_ORGANIZATION_PLACEHOLDER) {
67
- qb.andWhere((sub) => {
68
- sub.whereNull(column).orWhere(column, GLOBAL_ORGANIZATION_PLACEHOLDER)
69
- })
70
- } else {
71
- qb.andWhere(column, stored)
67
+ return qb.where((eb: any) => eb.or([
68
+ eb(column as any, 'is', null),
69
+ eb(column as any, '=', GLOBAL_ORGANIZATION_PLACEHOLDER),
70
+ ]))
72
71
  }
72
+ return qb.where(column as any, '=', stored)
73
73
  }
74
74
 
75
75
  async function fetchCoverageRow(
76
- knex: Knex,
76
+ db: Kysely<any>,
77
77
  scope: CoverageScope
78
78
  ): Promise<(CoverageRow & { organization_id: string | null }) | null> {
79
79
  const { entityType, tenantId, organizationId, withDeleted } = scope
80
- const row = await knex('entity_index_coverage')
81
- .select(['base_count', 'indexed_count', 'vector_indexed_count', 'refreshed_at', 'organization_id'])
82
- .where('entity_type', entityType)
83
- .where('tenant_id', tenantId ?? null)
84
- .where('with_deleted', withDeleted === true)
85
- .modify((qb) => applyOrganizationCondition(qb, 'organization_id', organizationId ?? null))
86
- .orderBy('refreshed_at', 'desc')
87
- .first<CoverageRow & { organization_id: string | null }>()
80
+ let query = db
81
+ .selectFrom('entity_index_coverage' as any)
82
+ .select([
83
+ 'base_count' as any,
84
+ 'indexed_count' as any,
85
+ 'vector_indexed_count' as any,
86
+ 'refreshed_at' as any,
87
+ 'organization_id' as any,
88
+ ])
89
+ .where('entity_type' as any, '=', entityType)
90
+ .where('with_deleted' as any, '=', withDeleted === true)
91
+ .orderBy('refreshed_at' as any, 'desc')
92
+ query = tenantId == null
93
+ ? query.where('tenant_id' as any, 'is', null as any)
94
+ : query.where('tenant_id' as any, '=', tenantId)
95
+ query = applyOrganizationCondition(query as any, 'organization_id', organizationId ?? null)
96
+ const row = await query.executeTakeFirst() as (CoverageRow & { organization_id: string | null }) | undefined
88
97
  return row ?? null
89
98
  }
90
99
 
91
100
  async function pruneDuplicateCoverageRows(
92
- knex: Knex,
101
+ db: Kysely<any>,
93
102
  scope: CoverageScope,
94
103
  keepId: string | null
95
- ) {
96
- const query = knex('entity_index_coverage')
97
- .where('entity_type', scope.entityType)
98
- .where('tenant_id', scope.tenantId ?? null)
99
- .where('with_deleted', scope.withDeleted === true)
100
- .modify((qb) => applyOrganizationCondition(qb, 'organization_id', scope.organizationId ?? null))
104
+ ): Promise<void> {
105
+ let query = db
106
+ .deleteFrom('entity_index_coverage' as any)
107
+ .where('entity_type' as any, '=', scope.entityType)
108
+ .where('with_deleted' as any, '=', scope.withDeleted === true)
109
+ query = scope.tenantId == null
110
+ ? query.where('tenant_id' as any, 'is', null as any)
111
+ : query.where('tenant_id' as any, '=', scope.tenantId)
112
+ query = applyOrganizationCondition(query as any, 'organization_id', scope.organizationId ?? null)
101
113
  if (keepId) {
102
- await query.andWhereNot('id', keepId).del()
103
- } else {
104
- await query.del()
114
+ query = query.where('id' as any, '!=', keepId)
105
115
  }
116
+ await query.execute()
106
117
  }
107
118
 
108
119
  async function upsertCoverageRow(
109
- knex: Knex,
120
+ db: Kysely<any>,
110
121
  scope: CoverageScope,
111
122
  counts: { baseCount: number; indexedCount: number; vectorIndexedCount: number }
112
- ) {
123
+ ): Promise<void> {
113
124
  const storedOrgId = normalizeOrganizationForStore(scope.organizationId ?? null)
114
125
  if (scope.organizationId == null) {
115
- await knex('entity_index_coverage')
116
- .where('entity_type', scope.entityType)
117
- .where('tenant_id', scope.tenantId ?? null)
118
- .where('with_deleted', scope.withDeleted === true)
119
- .whereNull('organization_id')
120
- .del()
126
+ let purge = db
127
+ .deleteFrom('entity_index_coverage' as any)
128
+ .where('entity_type' as any, '=', scope.entityType)
129
+ .where('with_deleted' as any, '=', scope.withDeleted === true)
130
+ .where('organization_id' as any, 'is', null as any)
131
+ purge = scope.tenantId == null
132
+ ? purge.where('tenant_id' as any, 'is', null as any)
133
+ : purge.where('tenant_id' as any, '=', scope.tenantId)
134
+ await purge.execute()
121
135
  }
122
136
 
123
- const rows = await knex('entity_index_coverage')
124
- .insert({
137
+ const rows = await db
138
+ .insertInto('entity_index_coverage' as any)
139
+ .values({
125
140
  entity_type: scope.entityType,
126
141
  tenant_id: scope.tenantId ?? null,
127
142
  organization_id: storedOrgId,
@@ -129,28 +144,30 @@ async function upsertCoverageRow(
129
144
  base_count: counts.baseCount,
130
145
  indexed_count: counts.indexedCount,
131
146
  vector_indexed_count: counts.vectorIndexedCount,
132
- refreshed_at: knex.fn.now(),
133
- })
134
- .onConflict(['entity_type', 'tenant_id', 'organization_id', 'with_deleted'])
135
- .merge({
136
- base_count: counts.baseCount,
137
- indexed_count: counts.indexedCount,
138
- vector_indexed_count: counts.vectorIndexedCount,
139
- refreshed_at: knex.fn.now(),
140
- })
141
- .returning<{ id: string }[]>('id')
147
+ refreshed_at: sql`now()`,
148
+ } as any)
149
+ .onConflict((oc: any) => oc
150
+ .columns(['entity_type', 'tenant_id', 'organization_id', 'with_deleted'])
151
+ .doUpdateSet({
152
+ base_count: counts.baseCount,
153
+ indexed_count: counts.indexedCount,
154
+ vector_indexed_count: counts.vectorIndexedCount,
155
+ refreshed_at: sql`now()`,
156
+ } as any))
157
+ .returning(['id' as any])
158
+ .execute() as Array<{ id: string }>
142
159
 
143
160
  const keepId = rows?.[0]?.id ?? null
144
- await pruneDuplicateCoverageRows(knex, scope, keepId)
161
+ await pruneDuplicateCoverageRows(db, scope, keepId)
145
162
  }
146
163
 
147
164
  export async function readCoverageSnapshot(
148
- knex: Knex,
165
+ db: Kysely<any>,
149
166
  scope: CoverageScope
150
167
  ): Promise<(CoverageRow & { baseCount: number; indexedCount: number; vectorIndexedCount: number }) | null> {
151
168
  const entityType = String(scope.entityType || '')
152
169
  if (!entityType) return null
153
- const row = await fetchCoverageRow(knex, {
170
+ const row = await fetchCoverageRow(db, {
154
171
  entityType,
155
172
  tenantId: scope.tenantId ?? null,
156
173
  organizationId: scope.organizationId ?? null,
@@ -174,11 +191,11 @@ export async function applyCoverageAdjustments(
174
191
  adjustments: CoverageAdjustment[]
175
192
  ): Promise<void> {
176
193
  if (!adjustments.length) return
177
- const knex = (em as any).getConnection().getKnex() as Knex
194
+ const db = (em as any).getKysely() as Kysely<any>
178
195
  const aggregated = aggregateAdjustments(adjustments)
179
196
  for (const entry of aggregated) {
180
197
  const scope = entry.scope
181
- const existing = await fetchCoverageRow(knex, scope)
198
+ const existing = await fetchCoverageRow(db, scope)
182
199
  const currentBase = existing ? toCount(existing.base_count) : 0
183
200
  const currentIndex = existing ? toCount(existing.indexed_count) : 0
184
201
  const currentVector = existing ? toCount(existing.vector_indexed_count) : 0
@@ -186,7 +203,7 @@ export async function applyCoverageAdjustments(
186
203
  const nextIndex = Math.max(currentIndex + entry.deltaIndex, 0)
187
204
  const nextVector = Math.max(currentVector + entry.deltaVector, 0)
188
205
 
189
- await upsertCoverageRow(knex, scope, {
206
+ await upsertCoverageRow(db, scope, {
190
207
  baseCount: nextBase,
191
208
  indexedCount: nextIndex,
192
209
  vectorIndexedCount: nextVector,
@@ -194,18 +211,24 @@ export async function applyCoverageAdjustments(
194
211
  }
195
212
  }
196
213
 
197
- export async function deleteCoverageForEntity(knex: Knex, entityType: string): Promise<void> {
214
+ export async function deleteCoverageForEntity(db: Kysely<any>, entityType: string): Promise<void> {
198
215
  if (!entityType) return
199
- await knex('entity_index_coverage').where({ entity_type: entityType }).del()
216
+ await db
217
+ .deleteFrom('entity_index_coverage' as any)
218
+ .where('entity_type' as any, '=', entityType)
219
+ .execute()
200
220
  }
201
221
 
202
- async function tableHasColumn(knex: Knex, table: string, column: string): Promise<boolean> {
222
+ async function tableHasColumn(db: Kysely<any>, table: string, column: string): Promise<boolean> {
203
223
  const key = `${table}.${column}`
204
224
  if (COLUMN_CACHE.has(key)) return COLUMN_CACHE.get(key)!
205
- const exists = await knex('information_schema.columns')
206
- .whereRaw('table_schema = current_schema()')
207
- .where({ table_name: table, column_name: column })
208
- .first()
225
+ const exists = await db
226
+ .selectFrom('information_schema.columns' as any)
227
+ .select(sql<number>`1`.as('present'))
228
+ .where(sql<boolean>`table_schema = current_schema()`)
229
+ .where('table_name' as any, '=', table)
230
+ .where('column_name' as any, '=', column)
231
+ .executeTakeFirst()
209
232
  const present = !!exists
210
233
  COLUMN_CACHE.set(key, present)
211
234
  return present
@@ -221,47 +244,51 @@ export async function refreshCoverageSnapshot(
221
244
  const organizationId = scope.organizationId ?? null
222
245
  const withDeleted = scope.withDeleted === true
223
246
 
224
- const knex = (em as any).getConnection().getKnex() as Knex
247
+ const db = (em as any).getKysely() as Kysely<any>
225
248
  const baseTable = resolveEntityTableName(em, entityType)
226
249
 
227
- const hasOrg = await tableHasColumn(knex, baseTable, 'organization_id')
228
- const hasTenant = await tableHasColumn(knex, baseTable, 'tenant_id')
229
- const hasDeleted = await tableHasColumn(knex, baseTable, 'deleted_at')
250
+ const hasOrg = await tableHasColumn(db, baseTable, 'organization_id')
251
+ const hasTenant = await tableHasColumn(db, baseTable, 'tenant_id')
252
+ const hasDeleted = await tableHasColumn(db, baseTable, 'deleted_at')
230
253
 
231
254
  if (organizationId !== null && !hasOrg) return
232
255
  if (tenantId !== null && !hasTenant) return
233
256
 
234
- let baseQuery = knex({ b: baseTable }).count({ count: '*' })
235
- if (organizationId !== null && hasOrg) baseQuery = baseQuery.where('b.organization_id', organizationId)
236
- if (tenantId !== null && hasTenant) baseQuery = baseQuery.where('b.tenant_id', tenantId)
237
- if (!withDeleted && hasDeleted) baseQuery = baseQuery.whereNull('b.deleted_at')
257
+ let baseQuery = db
258
+ .selectFrom(`${baseTable} as b` as any)
259
+ .select(sql`count(*)`.as('count'))
260
+ if (organizationId !== null && hasOrg) baseQuery = baseQuery.where('b.organization_id' as any, '=', organizationId)
261
+ if (tenantId !== null && hasTenant) baseQuery = baseQuery.where('b.tenant_id' as any, '=', tenantId)
262
+ if (!withDeleted && hasDeleted) baseQuery = baseQuery.where('b.deleted_at' as any, 'is', null as any)
238
263
 
239
- const baseRow = await baseQuery.first()
264
+ const baseRow = await baseQuery.executeTakeFirst() as { count: unknown } | undefined
240
265
  const baseCount = toCount(baseRow?.count)
241
266
 
242
- let indexQuery = knex({ ei: 'entity_indexes' })
243
- .count({ count: '*' })
244
- .where('ei.entity_type', entityType)
245
- if (organizationId !== null) indexQuery = indexQuery.where('ei.organization_id', organizationId)
246
- if (tenantId !== null) indexQuery = indexQuery.where('ei.tenant_id', tenantId)
247
- if (!withDeleted) indexQuery = indexQuery.whereNull('ei.deleted_at')
267
+ let indexQuery = db
268
+ .selectFrom('entity_indexes as ei' as any)
269
+ .select(sql`count(*)`.as('count'))
270
+ .where('ei.entity_type' as any, '=', entityType)
271
+ if (organizationId !== null) indexQuery = indexQuery.where('ei.organization_id' as any, '=', organizationId)
272
+ if (tenantId !== null) indexQuery = indexQuery.where('ei.tenant_id' as any, '=', tenantId)
273
+ if (!withDeleted) indexQuery = indexQuery.where('ei.deleted_at' as any, 'is', null as any)
248
274
 
249
- const indexRow = await indexQuery.first()
275
+ const indexRow = await indexQuery.executeTakeFirst() as { count: unknown } | undefined
250
276
  const indexCount = toCount(indexRow?.count)
251
277
 
252
278
  // Count vector entries directly from database
253
279
  let vectorCount: number | undefined
254
- const hasVectorTable = await tableHasColumn(knex, 'vector_search', 'entity_id')
280
+ const hasVectorTable = await tableHasColumn(db, 'vector_search', 'entity_id')
255
281
  if (hasVectorTable && typeof tenantId === 'string' && tenantId.length > 0) {
256
282
  try {
257
- let vectorQuery = knex('vector_search')
258
- .count({ count: 1 })
259
- .where('entity_id', entityType)
260
- .where('tenant_id', tenantId)
283
+ let vectorQuery = db
284
+ .selectFrom('vector_search' as any)
285
+ .select(sql`count(*)`.as('count'))
286
+ .where('entity_id' as any, '=', entityType)
287
+ .where('tenant_id' as any, '=', tenantId)
261
288
  if (organizationId !== null) {
262
- vectorQuery = vectorQuery.where('organization_id', organizationId)
289
+ vectorQuery = vectorQuery.where('organization_id' as any, '=', organizationId)
263
290
  }
264
- const vectorRow = await vectorQuery.first()
291
+ const vectorRow = await vectorQuery.executeTakeFirst() as { count: unknown } | undefined
265
292
  vectorCount = toCount(vectorRow?.count)
266
293
  } catch (err) {
267
294
  console.warn('[query_index] Failed to resolve vector count for coverage snapshot', {
@@ -288,11 +315,11 @@ export async function writeCoverageCounts(
288
315
  ): Promise<void> {
289
316
  const entityType = String(scope.entityType || '')
290
317
  if (!entityType) return
291
- const knex = (em as any).getConnection().getKnex() as Knex
318
+ const db = (em as any).getKysely() as Kysely<any>
292
319
  const tenantId = scope.tenantId ?? null
293
320
  const organizationId = scope.organizationId ?? null
294
321
  const withDeleted = scope.withDeleted === true
295
- const existing = await fetchCoverageRow(knex, {
322
+ const existing = await fetchCoverageRow(db, {
296
323
  entityType,
297
324
  tenantId,
298
325
  organizationId,
@@ -307,7 +334,7 @@ export async function writeCoverageCounts(
307
334
  const vectorCount = counts.vectorCount !== undefined
308
335
  ? Math.max(0, Math.trunc(toCount(counts.vectorCount)))
309
336
  : Math.max(0, Math.trunc(toCount(existing?.vector_indexed_count)))
310
- await upsertCoverageRow(knex, { entityType, tenantId, organizationId, withDeleted }, {
337
+ await upsertCoverageRow(db, { entityType, tenantId, organizationId, withDeleted }, {
311
338
  baseCount,
312
339
  indexedCount: indexCount,
313
340
  vectorIndexedCount: vectorCount,