@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,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
  import { resolveTenantEncryptionService } from '@open-mercato/shared/lib/encryption/customFieldValues'
5
5
  import { decryptIndexDocForSearch, encryptIndexDocForStorage } from '@open-mercato/shared/lib/encryption/indexDoc'
@@ -41,7 +41,7 @@ const COVERAGE_REFRESH_THROTTLE_MS = 5 * 60 * 1000
41
41
  const lastCoverageReset = new Map<string, number>()
42
42
 
43
43
  async function cleanupLegacyJobScopes(
44
- knex: Knex,
44
+ db: Kysely<any>,
45
45
  options: {
46
46
  entityType: string
47
47
  organizationId: string | null
@@ -49,12 +49,13 @@ async function cleanupLegacyJobScopes(
49
49
  activePartitionCount: number | null
50
50
  },
51
51
  ): Promise<void> {
52
- await knex('entity_index_jobs')
53
- .where('entity_type', options.entityType)
54
- .andWhereRaw('organization_id is not distinct from ?', [options.organizationId])
55
- .andWhereRaw('tenant_id is not distinct from ?', [options.tenantId])
56
- .andWhereRaw('partition_count is distinct from ?', [options.activePartitionCount])
57
- .del()
52
+ await db
53
+ .deleteFrom('entity_index_jobs' as any)
54
+ .where('entity_type' as any, '=', options.entityType)
55
+ .where(sql<boolean>`organization_id is not distinct from ${options.organizationId}`)
56
+ .where(sql<boolean>`tenant_id is not distinct from ${options.tenantId}`)
57
+ .where(sql<boolean>`partition_count is distinct from ${options.activePartitionCount}`)
58
+ .execute()
58
59
  }
59
60
 
60
61
  function toNumber(value: unknown): number {
@@ -66,10 +67,15 @@ function toNumber(value: unknown): number {
66
67
  return 0
67
68
  }
68
69
 
69
- async function getColumnSet(knex: Knex, tableName: string): Promise<Set<string>> {
70
+ async function getColumnSet(db: Kysely<any>, tableName: string): Promise<Set<string>> {
70
71
  try {
71
- const info = await knex(tableName).columnInfo()
72
- return new Set(Object.keys(info).map((key) => key.toLowerCase()))
72
+ const rows = await db
73
+ .selectFrom('information_schema.columns' as any)
74
+ .select(['column_name' as any])
75
+ .where(sql<boolean>`table_schema = current_schema()`)
76
+ .where('table_name' as any, '=', tableName)
77
+ .execute() as Array<{ column_name: string }>
78
+ return new Set(rows.map((row) => String(row.column_name).toLowerCase()))
73
79
  } catch {
74
80
  return new Set<string>()
75
81
  }
@@ -111,7 +117,7 @@ export async function reindexEntity(
111
117
  : null
112
118
  const resetCoverage = options?.resetCoverage ?? (!usingPartitions || partitionIndex === 0)
113
119
 
114
- const knex = (em as any).getConnection().getKnex() as Knex
120
+ const db = (em as any).getKysely() as Kysely<any>
115
121
  const table = resolveEntityTableName(em, entityType)
116
122
  if (entityType === 'query_index:search_token' || table === 'search_tokens') {
117
123
  return {
@@ -121,7 +127,7 @@ export async function reindexEntity(
121
127
  scopes: [],
122
128
  }
123
129
  }
124
- const columns = await getColumnSet(knex, table)
130
+ const columns = await getColumnSet(db, table)
125
131
  const hasOrgCol = columns.has('organization_id')
126
132
  const hasTenantCol = columns.has('tenant_id')
127
133
  const hasDeletedCol = columns.has('deleted_at')
@@ -135,16 +141,16 @@ export async function reindexEntity(
135
141
  }
136
142
 
137
143
  if (!force) {
138
- const activeJob = await (async () => {
139
- let query = knex('entity_index_jobs')
140
- .where('entity_type', entityType)
141
- .whereNull('finished_at')
142
- query = query.whereRaw('organization_id is not distinct from ?', [null])
143
- query = query.whereRaw('tenant_id is not distinct from ?', [tenantId ?? null])
144
- query = query.whereRaw('partition_index is not distinct from ?', [partitionIndex])
145
- query = query.whereRaw('partition_count is not distinct from ?', [usingPartitions ? partitionCountRaw : null])
146
- return query.first()
147
- })()
144
+ const activeJob = await db
145
+ .selectFrom('entity_index_jobs' as any)
146
+ .select(['id' as any])
147
+ .where('entity_type' as any, '=', entityType)
148
+ .where('finished_at' as any, 'is', null as any)
149
+ .where(sql<boolean>`organization_id is not distinct from ${null}`)
150
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
151
+ .where(sql<boolean>`partition_index is not distinct from ${partitionIndex}`)
152
+ .where(sql<boolean>`partition_count is not distinct from ${usingPartitions ? partitionCountRaw : null}`)
153
+ .executeTakeFirst()
148
154
  if (activeJob) {
149
155
  return {
150
156
  processed: 0,
@@ -156,7 +162,7 @@ export async function reindexEntity(
156
162
  }
157
163
 
158
164
  if (resetCoverage) {
159
- await cleanupLegacyJobScopes(knex, {
165
+ await cleanupLegacyJobScopes(db, {
160
166
  entityType,
161
167
  organizationId: jobScope.organizationId ?? null,
162
168
  tenantId: jobScope.tenantId ?? null,
@@ -165,19 +171,24 @@ export async function reindexEntity(
165
171
  }
166
172
 
167
173
  const scopeKey = (tenantValue: string | null, orgValue: string | null) => `${tenantValue ?? '__null__'}|${orgValue ?? '__null__'}`
168
- const baseWhere = (builder: Knex.QueryBuilder<any, any>) => {
169
- if (hasDeletedCol) builder.whereNull('b.deleted_at')
174
+
175
+ const applyBaseWhere = <QB extends { where: (...args: any[]) => QB }>(q: QB): QB => {
176
+ let chain = q
177
+ if (hasDeletedCol) chain = chain.where('b.deleted_at' as any, 'is', null as any)
170
178
  if (tenantId !== undefined && hasTenantCol) {
171
- if (tenantId === null) builder.whereNull('b.tenant_id')
172
- else builder.where('b.tenant_id', tenantId)
179
+ chain = tenantId === null
180
+ ? chain.where('b.tenant_id' as any, 'is', null as any)
181
+ : chain.where('b.tenant_id' as any, '=', tenantId)
173
182
  }
174
183
  if (organizationId !== undefined && hasOrgCol) {
175
- if (organizationId === null) builder.whereNull('b.organization_id')
176
- else builder.where('b.organization_id', organizationId)
184
+ chain = organizationId === null
185
+ ? chain.where('b.organization_id' as any, 'is', null as any)
186
+ : chain.where('b.organization_id' as any, '=', organizationId)
177
187
  }
178
188
  if (usingPartitions && partitionIndex !== null) {
179
- builder.whereRaw('mod(abs(hashtext(b.id::text)), ?) = ?', [partitionCountRaw, partitionIndex])
189
+ chain = chain.where(sql<boolean>`mod(abs(hashtext(b.id::text)), ${partitionCountRaw}) = ${partitionIndex}`)
180
190
  }
191
+ return chain
181
192
  }
182
193
 
183
194
  type ScopeStats = { tenantId: string | null; organizationId: string | null; count: number }
@@ -191,17 +202,16 @@ export async function reindexEntity(
191
202
  const groupByOrg = hasOrgCol && organizationId === undefined
192
203
 
193
204
  if (groupByTenant || groupByOrg) {
194
- const rows = await knex({ b: table })
195
- .modify(baseWhere)
196
- .modify((qb) => {
197
- if (groupByTenant) qb.select(knex.raw('b.tenant_id as tenant_id'))
198
- if (groupByOrg) qb.select(knex.raw('b.organization_id as organization_id'))
199
- })
200
- .count<{ count: unknown }[]>({ count: '*' })
201
- .modify((qb) => {
202
- if (groupByTenant) qb.groupBy('b.tenant_id')
203
- if (groupByOrg) qb.groupBy('b.organization_id')
204
- })
205
+ let groupQuery = applyBaseWhere(
206
+ db.selectFrom(`${table} as b` as any).select(sql<number>`count(*)`.as('count')),
207
+ )
208
+ if (groupByTenant) {
209
+ groupQuery = groupQuery.select('b.tenant_id as tenant_id' as any).groupBy('b.tenant_id' as any)
210
+ }
211
+ if (groupByOrg) {
212
+ groupQuery = groupQuery.select('b.organization_id as organization_id' as any).groupBy('b.organization_id' as any)
213
+ }
214
+ const rows = await groupQuery.execute() as Array<Record<string, unknown>>
205
215
  for (const row of rows) {
206
216
  const bucketTenant = groupByTenant
207
217
  ? ((row as any)?.tenant_id ?? null)
@@ -212,25 +222,26 @@ export async function reindexEntity(
212
222
  registerBaseCount(bucketTenant, bucketOrg, toNumber((row as any)?.count))
213
223
  }
214
224
  } else {
215
- const row = await knex({ b: table })
216
- .modify(baseWhere)
217
- .count({ count: '*' })
218
- .first()
225
+ const row = await applyBaseWhere(
226
+ db.selectFrom(`${table} as b` as any).select(sql<number>`count(*)`.as('count')),
227
+ ).executeTakeFirst() as { count: unknown } | undefined
219
228
  const bucketTenant = tenantId === undefined ? null : tenantId ?? null
220
229
  const bucketOrg = organizationId === undefined ? null : organizationId ?? null
221
230
  registerBaseCount(bucketTenant, bucketOrg, toNumber(row?.count))
222
231
  }
223
232
 
224
233
  const total = Array.from(baseCounts.values()).reduce((acc, value) => acc + (Number.isFinite(value.count) ? value.count : 0), 0)
225
- await prepareJob(knex, jobScope, 'reindexing', { totalCount: total })
226
- const jobRow = await knex('entity_index_jobs')
227
- .where({ entity_type: entityType })
228
- .whereNull('organization_id')
229
- .andWhereRaw('tenant_id is not distinct from ?', [tenantId ?? null])
230
- .andWhereRaw('partition_index is not distinct from ?', [partitionIndex])
231
- .andWhereRaw('partition_count is not distinct from ?', [usingPartitions ? partitionCountRaw : null])
232
- .orderBy('started_at', 'desc')
233
- .first<{ started_at: Date }>()
234
+ await prepareJob(db, jobScope, 'reindexing', { totalCount: total })
235
+ const jobRow = await db
236
+ .selectFrom('entity_index_jobs' as any)
237
+ .select(['started_at' as any])
238
+ .where('entity_type' as any, '=', entityType)
239
+ .where('organization_id' as any, 'is', null as any)
240
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
241
+ .where(sql<boolean>`partition_index is not distinct from ${partitionIndex}`)
242
+ .where(sql<boolean>`partition_count is not distinct from ${usingPartitions ? partitionCountRaw : null}`)
243
+ .orderBy('started_at' as any, 'desc')
244
+ .executeTakeFirst() as { started_at: Date | string } | undefined
234
245
  const jobStartedAt = jobRow?.started_at ? new Date(jobRow.started_at) : new Date()
235
246
  const deriveOrg = deriveOrgFromId.has(entityType)
236
247
  ? (row: AnyRow) => String(row.id)
@@ -259,25 +270,25 @@ export async function reindexEntity(
259
270
 
260
271
  if (resetCoverage) {
261
272
  if (force) {
262
- await knex('entity_indexes')
263
- .where('entity_type', entityType)
264
- .modify((qb) => {
265
- if (tenantId !== undefined) {
266
- qb.andWhereRaw('tenant_id is not distinct from ?', [tenantId ?? null])
267
- }
268
- if (organizationId !== undefined) {
269
- qb.andWhereRaw('organization_id is not distinct from ?', [organizationId ?? null])
270
- }
271
- })
272
- .del()
273
- .catch((error) => {
274
- console.warn('[HybridQueryEngine] Failed to purge index rows before force reindex', {
275
- entityType,
276
- tenantId: tenantId ?? null,
277
- organizationId: organizationId ?? null,
278
- error: error instanceof Error ? error.message : error,
279
- })
273
+ try {
274
+ let purgeQuery = db
275
+ .deleteFrom('entity_indexes' as any)
276
+ .where('entity_type' as any, '=', entityType)
277
+ if (tenantId !== undefined) {
278
+ purgeQuery = purgeQuery.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
279
+ }
280
+ if (organizationId !== undefined) {
281
+ purgeQuery = purgeQuery.where(sql<boolean>`organization_id is not distinct from ${organizationId ?? null}`)
282
+ }
283
+ await purgeQuery.execute()
284
+ } catch (error) {
285
+ console.warn('[HybridQueryEngine] Failed to purge index rows before force reindex', {
286
+ entityType,
287
+ tenantId: tenantId ?? null,
288
+ organizationId: organizationId ?? null,
289
+ error: error instanceof Error ? error.message : error,
280
290
  })
291
+ }
281
292
 
282
293
  if (emitVectorize && eventBus) {
283
294
  if (tenantId !== undefined) {
@@ -326,15 +337,17 @@ export async function reindexEntity(
326
337
 
327
338
  try {
328
339
  while (true) {
329
- let query = knex({ b: table })
330
- .modify(baseWhere)
331
- .select('b.*')
332
- .orderBy('b.id', 'asc')
333
- .limit(batchSize)
340
+ let query = applyBaseWhere(
341
+ db
342
+ .selectFrom(`${table} as b` as any)
343
+ .selectAll('b' as any)
344
+ .orderBy('b.id' as any, 'asc')
345
+ .limit(batchSize),
346
+ )
334
347
  if (lastId !== null) {
335
- query = query.where('b.id', '>', lastId)
348
+ query = query.where('b.id' as any, '>', lastId)
336
349
  }
337
- const rows = await query as AnyRow[]
350
+ const rows = await query.execute() as AnyRow[]
338
351
  if (!rows.length) break
339
352
 
340
353
  const encryption = resolveTenantEncryptionService(em as any)
@@ -380,7 +393,7 @@ export async function reindexEntity(
380
393
  return result
381
394
  }
382
395
 
383
- await upsertIndexBatch(knex, entityType, rows, scopeOverrides, { deriveOrganizationId: deriveOrg, encryptDoc, decryptDoc })
396
+ await upsertIndexBatch(db, entityType, rows, scopeOverrides, { deriveOrganizationId: deriveOrg, encryptDoc, decryptDoc })
384
397
 
385
398
  const coverageDeltas = new Map<string, { tenantId: string | null; organizationId: string | null; delta: number }>()
386
399
  for (const row of rows) {
@@ -439,10 +452,10 @@ export async function reindexEntity(
439
452
  processed += rows.length
440
453
  lastId = String(rows[rows.length - 1]!.id)
441
454
  options?.onProgress?.({ processed, total, chunkSize: rows.length })
442
- await updateJobProgress(knex, jobScope, rows.length)
455
+ await updateJobProgress(db, jobScope, rows.length)
443
456
  }
444
457
 
445
- await purgeOrphans(knex, {
458
+ await purgeOrphans(db, {
446
459
  entityType,
447
460
  tenantId,
448
461
  organizationId,
@@ -481,7 +494,7 @@ export async function reindexEntity(
481
494
  )
482
495
  }
483
496
  } finally {
484
- await finalizeJob(knex, jobScope)
497
+ await finalizeJob(db, jobScope)
485
498
  }
486
499
 
487
500
  return {
@@ -1,8 +1,17 @@
1
- import type { Knex } from 'knex'
1
+ import { type Kysely, sql } from 'kysely'
2
2
  import { resolveSearchConfig, type SearchConfig } from '@open-mercato/shared/lib/search/config'
3
3
  import { tokenizeText } from '@open-mercato/shared/lib/search/tokenize'
4
4
  import { parseBooleanToken } from '@open-mercato/shared/lib/boolean'
5
5
 
6
+ const INSERT_BATCH_SIZE = 500
7
+
8
+ function chunk<T>(items: T[], size: number): T[][] {
9
+ if (size <= 0) return [items]
10
+ const out: T[][] = []
11
+ for (let i = 0; i < items.length; i += size) out.push(items.slice(i, i + size))
12
+ return out
13
+ }
14
+
6
15
  export type SearchTokenRow = {
7
16
  entity_type: string
8
17
  entity_id: string
@@ -130,7 +139,7 @@ function buildFieldPairs(recordId: string, doc?: Record<string, unknown> | null)
130
139
  }
131
140
 
132
141
  export async function replaceSearchTokensForRecord(
133
- knex: Knex,
142
+ db: Kysely<any>,
134
143
  params: BuildTokenOptions
135
144
  ): Promise<void> {
136
145
  const rows = buildSearchTokenRows(params)
@@ -140,38 +149,48 @@ export async function replaceSearchTokensForRecord(
140
149
  const tenantId = params.tenantId ?? null
141
150
  const fieldPairs = buildFieldPairs(String(params.recordId), params.doc)
142
151
 
143
- await knex.transaction(async (trx) => {
144
- const deleteQuery = trx('search_tokens')
145
- .where({ entity_type: params.entityType })
146
- .andWhereRaw('organization_id is not distinct from ?', [organizationId])
147
- .andWhereRaw('tenant_id is not distinct from ?', [tenantId])
148
- if (fieldPairs.length) deleteQuery.whereIn(['entity_id', 'field'], fieldPairs)
149
- else deleteQuery.where('entity_id', String(params.recordId))
150
- await deleteQuery.del()
152
+ await db.transaction().execute(async (trx) => {
153
+ let deleteQuery = trx
154
+ .deleteFrom('search_tokens' as any)
155
+ .where('entity_type' as any, '=', params.entityType)
156
+ .where(sql<boolean>`organization_id is not distinct from ${organizationId}`)
157
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantId}`)
158
+ if (fieldPairs.length) {
159
+ deleteQuery = deleteQuery.where((eb: any) => eb.or(
160
+ fieldPairs.map(([rid, field]) => eb.and([
161
+ eb('entity_id' as any, '=', rid),
162
+ eb('field' as any, '=', field),
163
+ ])),
164
+ ))
165
+ } else {
166
+ deleteQuery = deleteQuery.where('entity_id' as any, '=', String(params.recordId))
167
+ }
168
+ await deleteQuery.execute()
151
169
  if (!rows.length) return
152
- const payloads = rows.map((row) => ({
153
- ...row,
154
- created_at: trx.fn.now(),
155
- }))
156
- await trx.batchInsert('search_tokens', payloads, 500)
170
+ const payloads = rows.map((row) => ({ ...row, created_at: sql`now()` }))
171
+ for (const batch of chunk(payloads, INSERT_BATCH_SIZE)) {
172
+ await trx.insertInto('search_tokens' as any).values(batch as any).execute()
173
+ }
157
174
  })
158
175
  }
159
176
 
160
177
  export async function deleteSearchTokensForRecord(
161
- knex: Knex,
178
+ db: Kysely<any>,
162
179
  params: { entityType: string; recordId: string; organizationId?: string | null; tenantId?: string | null }
163
180
  ): Promise<void> {
164
181
  const organizationId = params.organizationId ?? null
165
182
  const tenantId = params.tenantId ?? null
166
- await knex('search_tokens')
167
- .where({ entity_type: params.entityType, entity_id: String(params.recordId) })
168
- .andWhereRaw('organization_id is not distinct from ?', [organizationId])
169
- .andWhereRaw('tenant_id is not distinct from ?', [tenantId])
170
- .del()
183
+ await db
184
+ .deleteFrom('search_tokens' as any)
185
+ .where('entity_type' as any, '=', params.entityType)
186
+ .where('entity_id' as any, '=', String(params.recordId))
187
+ .where(sql<boolean>`organization_id is not distinct from ${organizationId}`)
188
+ .where(sql<boolean>`tenant_id is not distinct from ${tenantId}`)
189
+ .execute()
171
190
  }
172
191
 
173
192
  export async function replaceSearchTokensForBatch(
174
- knex: Knex,
193
+ db: Kysely<any>,
175
194
  payloads: Array<BuildTokenOptions & { doc: Record<string, unknown> }>
176
195
  ): Promise<void> {
177
196
  if (!payloads.length) return
@@ -183,7 +202,11 @@ export async function replaceSearchTokensForBatch(
183
202
  const entityType = payloads[0]?.entityType
184
203
  if (!entityType) return
185
204
  const ids = payloads.map((p) => String(p.recordId))
186
- await knex('search_tokens').where({ entity_type: entityType }).whereIn('entity_id', ids).del()
205
+ await db
206
+ .deleteFrom('search_tokens' as any)
207
+ .where('entity_type' as any, '=', entityType)
208
+ .where('entity_id' as any, 'in', ids)
209
+ .execute()
187
210
  return
188
211
  }
189
212
 
@@ -218,21 +241,29 @@ export async function replaceSearchTokensForBatch(
218
241
  seenPairsByScope.set(key, seen)
219
242
  }
220
243
 
221
- await knex.transaction(async (trx) => {
244
+ await db.transaction().execute(async (trx) => {
222
245
  for (const [key, bucket] of scopeBuckets.entries()) {
223
246
  const pairs = fieldPairsByScope.get(key) ?? []
224
- const deleteQuery = trx('search_tokens')
225
- .where({ entity_type: payloads[0].entityType })
226
- .andWhereRaw('organization_id is not distinct from ?', [bucket.organizationId])
227
- .andWhereRaw('tenant_id is not distinct from ?', [bucket.tenantId])
228
- if (pairs.length) deleteQuery.whereIn(['entity_id', 'field'], pairs)
229
- else deleteQuery.whereIn('entity_id', Array.from(bucket.ids))
230
- await deleteQuery.del()
247
+ let deleteQuery = trx
248
+ .deleteFrom('search_tokens' as any)
249
+ .where('entity_type' as any, '=', payloads[0].entityType)
250
+ .where(sql<boolean>`organization_id is not distinct from ${bucket.organizationId}`)
251
+ .where(sql<boolean>`tenant_id is not distinct from ${bucket.tenantId}`)
252
+ if (pairs.length) {
253
+ deleteQuery = deleteQuery.where((eb: any) => eb.or(
254
+ pairs.map(([rid, field]) => eb.and([
255
+ eb('entity_id' as any, '=', rid),
256
+ eb('field' as any, '=', field),
257
+ ])),
258
+ ))
259
+ } else {
260
+ deleteQuery = deleteQuery.where('entity_id' as any, 'in', Array.from(bucket.ids))
261
+ }
262
+ await deleteQuery.execute()
263
+ }
264
+ const payloadWithTimestamps = rows.map((row) => ({ ...row, created_at: sql`now()` }))
265
+ for (const batch of chunk(payloadWithTimestamps, INSERT_BATCH_SIZE)) {
266
+ await trx.insertInto('search_tokens' as any).values(batch as any).execute()
231
267
  }
232
- const payloadWithTimestamps = rows.map((row) => ({
233
- ...row,
234
- created_at: trx.fn.now(),
235
- }))
236
- await trx.batchInsert('search_tokens', payloadWithTimestamps, 500)
237
268
  })
238
269
  }
@@ -1,4 +1,4 @@
1
- import type { Knex } from 'knex'
1
+ import { type Kysely, sql } from 'kysely'
2
2
 
3
3
  type PurgeOrphansOptions = {
4
4
  entityType: string
@@ -10,23 +10,20 @@ type PurgeOrphansOptions = {
10
10
  }
11
11
 
12
12
  export async function purgeOrphans(
13
- knex: Knex,
13
+ db: Kysely<any>,
14
14
  options: PurgeOrphansOptions,
15
15
  ): Promise<void> {
16
16
  const { entityType, tenantId, partitionIndex, partitionCount, startedAt } = options
17
- await knex('entity_indexes')
18
- .where('entity_type', entityType)
19
- .modify((qb) => {
20
- if (tenantId !== undefined) {
21
- qb.andWhereRaw('tenant_id is not distinct from ?', [tenantId ?? null])
22
- }
23
- if (options.organizationId !== undefined) {
24
- qb.andWhereRaw('organization_id is not distinct from ?', [options.organizationId ?? null])
25
- }
26
- if (partitionIndex != null && partitionCount != null) {
27
- qb.andWhereRaw('mod(abs(hashtext(entity_id::text)), ?) = ?', [partitionCount, partitionIndex])
28
- }
29
- })
30
- .andWhere('updated_at', '<', startedAt)
31
- .del()
17
+ let q = db.deleteFrom('entity_indexes' as any).where('entity_type' as any, '=', entityType)
18
+ if (tenantId !== undefined) {
19
+ q = q.where(sql<boolean>`tenant_id is not distinct from ${tenantId ?? null}`)
20
+ }
21
+ if (options.organizationId !== undefined) {
22
+ q = q.where(sql<boolean>`organization_id is not distinct from ${options.organizationId ?? null}`)
23
+ }
24
+ if (partitionIndex != null && partitionCount != null) {
25
+ q = q.where(sql<boolean>`mod(abs(hashtext(entity_id::text)), ${partitionCount}) = ${partitionIndex}`)
26
+ }
27
+ q = q.where('updated_at' as any, '<', startedAt as any)
28
+ await q.execute()
32
29
  }
@@ -32,12 +32,13 @@ export async function loadQueryIndexRowScope(
32
32
  entityType: string,
33
33
  recordId: string
34
34
  ): Promise<QueryIndexScope | null> {
35
- const knex = (em as any).getConnection().getKnex()
35
+ const db = em.getKysely<any>()
36
36
  const table = resolveEntityTableName(em, entityType)
37
- const row = await knex(table)
38
- .select(['organization_id', 'tenant_id'])
39
- .where({ id: recordId })
40
- .first()
37
+ const row = await db
38
+ .selectFrom(table as any)
39
+ .select(['organization_id' as any, 'tenant_id' as any])
40
+ .where('id' as any, '=', recordId)
41
+ .executeTakeFirst() as { organization_id: string | null; tenant_id: string | null } | undefined
41
42
 
42
43
  if (!row) {
43
44
  return null
@@ -1,5 +1,6 @@
1
1
  import { recordIndexerError } from '@open-mercato/shared/lib/indexers/error-log'
2
2
  import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
3
+ import { sql } from 'kysely'
3
4
  import { markDeleted } from '../lib/indexer'
4
5
  import { applyCoverageAdjustments, createCoverageAdjustments } from '../lib/coverage'
5
6
  import { loadQueryIndexRowScope, resolveQueryIndexRecordScope } from '../lib/subscriber-scope'
@@ -33,13 +34,15 @@ export default async function handle(payload: any, ctx: { resolve: <T=any>(name:
33
34
  let baseDelta = 0
34
35
  let baseCheckSucceeded = false
35
36
  try {
36
- const knex = (em as any).getConnection().getKnex()
37
+ const db = (em as any).getKysely()
37
38
  const table = resolveEntityTableName(em, entityType)
38
- const row = await knex(table)
39
- .select(['deleted_at'])
40
- .where({ id: recordId, organization_id: organizationId })
41
- .andWhereRaw('tenant_id is not distinct from ?', [tenantId])
42
- .first()
39
+ const row = await db
40
+ .selectFrom(table as any)
41
+ .select(['deleted_at' as any])
42
+ .where('id' as any, '=', recordId)
43
+ .where('organization_id' as any, organizationId === null ? 'is' : '=', organizationId as any)
44
+ .where(sql`tenant_id is not distinct from ${tenantId}`)
45
+ .executeTakeFirst() as { deleted_at: Date | null } | undefined
43
46
  const baseMissing = !row
44
47
  const baseDeleted = baseMissing || (row && row.deleted_at != null)
45
48
  baseCheckSucceeded = true
@@ -140,7 +140,7 @@ const unassignResourceTagCommand: CommandHandler<ResourcesResourceTagAssignmentI
140
140
  organizationId: parsed.organizationId,
141
141
  })
142
142
  if (!existing) throw new CrudHttpError(404, { error: 'Tag assignment not found.' })
143
- await em.remove(existing)
143
+ await em.remove(existing).flush()
144
144
  await em.flush()
145
145
 
146
146
  const dataEngine = (ctx.container.resolve('dataEngine') as DataEngine)
@@ -40,7 +40,7 @@ const createTagCommand: CommandHandler<ResourcesResourceTagCreateInput, { tagId:
40
40
  createdAt: new Date(),
41
41
  updatedAt: new Date(),
42
42
  })
43
- await em.persistAndFlush(tag)
43
+ await em.persist(tag).flush()
44
44
  return { tagId: tag.id }
45
45
  },
46
46
  buildLog: async ({ input, result, ctx }) => {
@@ -1,4 +1,5 @@
1
- import { Entity, PrimaryKey, Property, Index, OneToMany, ManyToOne, Collection, Unique } from '@mikro-orm/core'
1
+ import { Collection } from '@mikro-orm/core'
2
+ import { Entity, Index, ManyToOne, OneToMany, PrimaryKey, Property, Unique } from '@mikro-orm/decorators/legacy'
2
3
 
3
4
  @Entity({ tableName: 'resources_resource_types' })
4
5
  @Index({ name: 'resources_resource_types_tenant_org_idx', properties: ['tenantId', 'organizationId'] })
@@ -87,7 +87,7 @@ const createDocumentAddress: CommandHandler<DocumentAddressCreateInput, { id: st
87
87
  order: input.documentKind === 'order' ? (document as SalesOrder) : null,
88
88
  quote: input.documentKind === 'quote' ? (document as SalesQuote) : null,
89
89
  })
90
- await em.persistAndFlush(entity)
90
+ await em.persist(entity).flush()
91
91
  return { id: entity.id }
92
92
  },
93
93
  }
@@ -158,7 +158,7 @@ const deleteDocumentAddress: CommandHandler<
158
158
  status: (document as SalesOrder).status ?? null,
159
159
  })
160
160
  }
161
- await em.removeAndFlush(entity)
161
+ await em.remove(entity).flush()
162
162
  return { ok: true }
163
163
  },
164
164
  }
@@ -122,7 +122,7 @@ async function requireContext(
122
122
  }
123
123
  }
124
124
  const repo = contextType === 'invoice' ? SalesInvoice : SalesCreditMemo
125
- const entity = await em.findOne(repo, { id: contextId })
125
+ const entity = await em.findOne(repo as any, { id: contextId }) as (SalesInvoice | SalesCreditMemo) | null
126
126
  if (!entity) {
127
127
  throw new CrudHttpError(404, { error: 'sales.notes.context_not_found' })
128
128
  }
@@ -33,7 +33,7 @@ const createTagCommand: CommandHandler<SalesTagCreateInput, { tagId: string }> =
33
33
  color: parsed.color ?? null,
34
34
  description: parsed.description ?? null,
35
35
  })
36
- await em.persistAndFlush(tag)
36
+ await em.persist(tag).flush()
37
37
  return { tagId: tag.id }
38
38
  },
39
39
  }