@open-mercato/core 0.5.1-develop.2691.d8a0934b37 → 0.5.1-develop.2694.732417c5ec
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.
- package/dist/modules/api_keys/data/entities.js +1 -1
- package/dist/modules/api_keys/data/entities.js.map +1 -1
- package/dist/modules/api_keys/services/apiKeyService.js +5 -5
- package/dist/modules/api_keys/services/apiKeyService.js.map +2 -2
- package/dist/modules/attachments/api/library/[id]/route.js +1 -1
- package/dist/modules/attachments/api/library/[id]/route.js.map +2 -2
- package/dist/modules/attachments/api/library/route.js +7 -9
- package/dist/modules/attachments/api/library/route.js.map +2 -2
- package/dist/modules/attachments/api/partitions/route.js +3 -3
- package/dist/modules/attachments/api/partitions/route.js.map +2 -2
- package/dist/modules/attachments/api/route.js +6 -5
- package/dist/modules/attachments/api/route.js.map +2 -2
- package/dist/modules/attachments/api/transfer/route.js +1 -1
- package/dist/modules/attachments/api/transfer/route.js.map +2 -2
- package/dist/modules/attachments/data/entities.js +2 -1
- package/dist/modules/attachments/data/entities.js.map +2 -2
- package/dist/modules/attachments/lib/ocrQueue.js +1 -1
- package/dist/modules/attachments/lib/ocrQueue.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/export/route.js.map +2 -2
- package/dist/modules/audit_logs/api/audit-logs/actions/route.js.map +2 -2
- package/dist/modules/audit_logs/data/entities.js +1 -1
- package/dist/modules/audit_logs/data/entities.js.map +1 -1
- package/dist/modules/audit_logs/services/actionLogService.js +77 -70
- package/dist/modules/audit_logs/services/actionLogService.js.map +2 -2
- package/dist/modules/auth/api/roles/acl/route.js +1 -1
- package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
- package/dist/modules/auth/api/users/acl/route.js +2 -2
- package/dist/modules/auth/api/users/acl/route.js.map +2 -2
- package/dist/modules/auth/api/users/resend-invite/route.js +1 -1
- package/dist/modules/auth/api/users/resend-invite/route.js.map +2 -2
- package/dist/modules/auth/cli.js +12 -6
- package/dist/modules/auth/cli.js.map +2 -2
- package/dist/modules/auth/commands/users.js +1 -1
- package/dist/modules/auth/commands/users.js.map +2 -2
- package/dist/modules/auth/data/entities.js +1 -1
- package/dist/modules/auth/data/entities.js.map +2 -2
- package/dist/modules/auth/lib/setup-app.js +3 -3
- package/dist/modules/auth/lib/setup-app.js.map +2 -2
- package/dist/modules/auth/services/authService.js +2 -2
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/business_rules/api/rules/route.js +3 -3
- package/dist/modules/business_rules/api/rules/route.js.map +2 -2
- package/dist/modules/business_rules/api/sets/[id]/members/route.js +7 -4
- package/dist/modules/business_rules/api/sets/[id]/members/route.js.map +2 -2
- package/dist/modules/business_rules/api/sets/route.js +3 -3
- package/dist/modules/business_rules/api/sets/route.js.map +2 -2
- package/dist/modules/business_rules/cli.js +1 -1
- package/dist/modules/business_rules/cli.js.map +2 -2
- package/dist/modules/business_rules/data/entities.js +2 -9
- package/dist/modules/business_rules/data/entities.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-engine.js +1 -1
- package/dist/modules/business_rules/lib/rule-engine.js.map +2 -2
- package/dist/modules/catalog/api/option-schemas/route.js +0 -1
- package/dist/modules/catalog/api/option-schemas/route.js.map +2 -2
- package/dist/modules/catalog/data/entities.js +2 -11
- package/dist/modules/catalog/data/entities.js.map +2 -2
- package/dist/modules/configs/data/entities.js +2 -1
- package/dist/modules/configs/data/entities.js.map +2 -2
- package/dist/modules/currencies/commands/fetch-configs.js +3 -3
- package/dist/modules/currencies/commands/fetch-configs.js.map +2 -2
- package/dist/modules/currencies/data/entities.js +1 -1
- package/dist/modules/currencies/data/entities.js.map +2 -2
- package/dist/modules/customer_accounts/api/signup.js +1 -1
- package/dist/modules/customer_accounts/api/signup.js.map +2 -2
- package/dist/modules/customer_accounts/data/entities.js +1 -1
- package/dist/modules/customer_accounts/data/entities.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerInvitationService.js +1 -1
- package/dist/modules/customer_accounts/services/customerInvitationService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerSessionService.js +1 -1
- package/dist/modules/customer_accounts/services/customerSessionService.js.map +2 -2
- package/dist/modules/customer_accounts/services/customerTokenService.js +12 -7
- package/dist/modules/customer_accounts/services/customerTokenService.js.map +2 -2
- package/dist/modules/customers/api/interactions/conflicts/route.js +19 -17
- package/dist/modules/customers/api/interactions/conflicts/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/counts/route.js +7 -6
- package/dist/modules/customers/api/interactions/counts/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/route.js +28 -42
- package/dist/modules/customers/api/interactions/route.js.map +2 -2
- package/dist/modules/customers/api/utils.js +29 -24
- package/dist/modules/customers/api/utils.js.map +2 -2
- package/dist/modules/customers/cli.js +45 -40
- package/dist/modules/customers/cli.js.map +2 -2
- package/dist/modules/customers/commands/dictionaries.js +1 -1
- package/dist/modules/customers/commands/dictionaries.js.map +2 -2
- package/dist/modules/customers/commands/tags.js +1 -1
- package/dist/modules/customers/commands/tags.js.map +2 -2
- package/dist/modules/customers/data/entities.js +2 -12
- package/dist/modules/customers/data/entities.js.map +2 -2
- package/dist/modules/customers/lib/interactionProjection.js +18 -15
- package/dist/modules/customers/lib/interactionProjection.js.map +2 -2
- package/dist/modules/customers/lib/personCompanyLinkTable.js +6 -8
- package/dist/modules/customers/lib/personCompanyLinkTable.js.map +2 -2
- package/dist/modules/dashboards/api/roles/widgets/route.js +1 -1
- package/dist/modules/dashboards/api/roles/widgets/route.js.map +2 -2
- package/dist/modules/dashboards/api/users/widgets/route.js +1 -1
- package/dist/modules/dashboards/api/users/widgets/route.js.map +2 -2
- package/dist/modules/dashboards/data/entities.js +1 -1
- package/dist/modules/dashboards/data/entities.js.map +1 -1
- package/dist/modules/data_sync/api/mappings/route.js +1 -1
- package/dist/modules/data_sync/api/mappings/route.js.map +2 -2
- package/dist/modules/data_sync/data/entities.js +2 -1
- package/dist/modules/data_sync/data/entities.js.map +2 -2
- package/dist/modules/data_sync/lib/id-mapping.js +1 -1
- package/dist/modules/data_sync/lib/id-mapping.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-run-service.js +1 -1
- package/dist/modules/data_sync/lib/sync-run-service.js.map +2 -2
- package/dist/modules/dictionaries/commands/factory.js +1 -1
- package/dist/modules/dictionaries/commands/factory.js.map +2 -2
- package/dist/modules/dictionaries/data/entities.js +2 -9
- package/dist/modules/dictionaries/data/entities.js.map +2 -2
- package/dist/modules/directory/commands/organizations.js +4 -4
- package/dist/modules/directory/commands/organizations.js.map +2 -2
- package/dist/modules/directory/data/entities.js +2 -1
- package/dist/modules/directory/data/entities.js.map +2 -2
- package/dist/modules/entities/api/definitions.js +2 -2
- package/dist/modules/entities/api/definitions.js.map +2 -2
- package/dist/modules/entities/api/encryption.js +2 -2
- package/dist/modules/entities/api/encryption.js.map +2 -2
- package/dist/modules/entities/api/relations/options.js +2 -2
- package/dist/modules/entities/api/relations/options.js.map +2 -2
- package/dist/modules/entities/cli.js +4 -4
- package/dist/modules/entities/cli.js.map +2 -2
- package/dist/modules/entities/data/entities.js +1 -1
- package/dist/modules/entities/data/entities.js.map +2 -2
- package/dist/modules/entities/lib/field-definitions.js +2 -2
- package/dist/modules/entities/lib/field-definitions.js.map +2 -2
- package/dist/modules/entities/lib/register.js +1 -1
- package/dist/modules/entities/lib/register.js.map +2 -2
- package/dist/modules/feature_toggles/data/entities.js +2 -9
- package/dist/modules/feature_toggles/data/entities.js.map +2 -2
- package/dist/modules/inbox_ops/api/proposals/counts/route.js +3 -6
- package/dist/modules/inbox_ops/api/proposals/counts/route.js.map +2 -2
- package/dist/modules/inbox_ops/data/entities.js +2 -8
- package/dist/modules/inbox_ops/data/entities.js.map +2 -2
- package/dist/modules/inbox_ops/lib/messagesIntegration.js +6 -6
- package/dist/modules/inbox_ops/lib/messagesIntegration.js.map +2 -2
- package/dist/modules/integrations/data/entities.js +2 -1
- package/dist/modules/integrations/data/entities.js.map +2 -2
- package/dist/modules/integrations/lib/credentials-service.js +1 -1
- package/dist/modules/integrations/lib/credentials-service.js.map +2 -2
- package/dist/modules/integrations/lib/log-service.js +1 -1
- package/dist/modules/integrations/lib/log-service.js.map +2 -2
- package/dist/modules/integrations/lib/state-service.js +1 -1
- package/dist/modules/integrations/lib/state-service.js.map +2 -2
- package/dist/modules/messages/api/route.js +90 -93
- package/dist/modules/messages/api/route.js.map +2 -2
- package/dist/modules/messages/api/unread-count/route.js +8 -7
- package/dist/modules/messages/api/unread-count/route.js.map +2 -2
- package/dist/modules/messages/commands/confirmations.js +1 -1
- package/dist/modules/messages/commands/confirmations.js.map +2 -2
- package/dist/modules/messages/commands/messages.js +3 -3
- package/dist/modules/messages/commands/messages.js.map +2 -2
- package/dist/modules/messages/data/entities.js +2 -1
- package/dist/modules/messages/data/entities.js.map +2 -2
- package/dist/modules/messages/lib/email-sender.js +1 -1
- package/dist/modules/messages/lib/email-sender.js.map +2 -2
- package/dist/modules/messages/lib/searchLookup.js +8 -8
- package/dist/modules/messages/lib/searchLookup.js.map +2 -2
- package/dist/modules/messages/lib/tokenConsumption.js +9 -4
- package/dist/modules/messages/lib/tokenConsumption.js.map +2 -2
- package/dist/modules/notifications/data/entities.js +2 -1
- package/dist/modules/notifications/data/entities.js.map +2 -2
- package/dist/modules/notifications/lib/notificationRecipients.js +15 -5
- package/dist/modules/notifications/lib/notificationRecipients.js.map +2 -2
- package/dist/modules/notifications/lib/notificationService.js +39 -34
- package/dist/modules/notifications/lib/notificationService.js.map +2 -2
- package/dist/modules/notifications/workers/create-notification.worker.js +14 -13
- package/dist/modules/notifications/workers/create-notification.worker.js.map +2 -2
- package/dist/modules/payment_gateways/api/transactions/route.js +2 -2
- package/dist/modules/payment_gateways/api/transactions/route.js.map +2 -2
- package/dist/modules/payment_gateways/data/entities.js +2 -1
- package/dist/modules/payment_gateways/data/entities.js.map +2 -2
- package/dist/modules/payment_gateways/lib/gateway-service.js +1 -1
- package/dist/modules/payment_gateways/lib/gateway-service.js.map +2 -2
- package/dist/modules/payment_gateways/lib/webhook-utils.js +2 -2
- package/dist/modules/payment_gateways/lib/webhook-utils.js.map +2 -2
- package/dist/modules/perspectives/data/entities.js +1 -1
- package/dist/modules/perspectives/data/entities.js.map +2 -2
- package/dist/modules/planner/data/entities.js +1 -1
- package/dist/modules/planner/data/entities.js.map +2 -2
- package/dist/modules/progress/data/entities.js +2 -1
- package/dist/modules/progress/data/entities.js.map +2 -2
- package/dist/modules/progress/lib/progressServiceImpl.js +1 -1
- package/dist/modules/progress/lib/progressServiceImpl.js.map +2 -2
- package/dist/modules/query_index/api/status.js +66 -57
- package/dist/modules/query_index/api/status.js.map +2 -2
- package/dist/modules/query_index/cli.js +39 -24
- package/dist/modules/query_index/cli.js.map +2 -2
- package/dist/modules/query_index/data/entities.js +1 -1
- package/dist/modules/query_index/data/entities.js.map +2 -2
- package/dist/modules/query_index/di.js +25 -13
- package/dist/modules/query_index/di.js.map +2 -2
- package/dist/modules/query_index/lib/batch.js +31 -33
- package/dist/modules/query_index/lib/batch.js.map +2 -2
- package/dist/modules/query_index/lib/coverage.js +63 -50
- package/dist/modules/query_index/lib/coverage.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +592 -588
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/lib/indexer.js +74 -47
- package/dist/modules/query_index/lib/indexer.js.map +2 -2
- package/dist/modules/query_index/lib/jobs.js +37 -24
- package/dist/modules/query_index/lib/jobs.js.map +2 -2
- package/dist/modules/query_index/lib/purge.js +19 -11
- package/dist/modules/query_index/lib/purge.js.map +2 -2
- package/dist/modules/query_index/lib/reindexer.js +47 -44
- package/dist/modules/query_index/lib/reindexer.js.map +2 -2
- package/dist/modules/query_index/lib/search-tokens.js +47 -25
- package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
- package/dist/modules/query_index/lib/stale.js +14 -12
- package/dist/modules/query_index/lib/stale.js.map +2 -2
- package/dist/modules/query_index/lib/subscriber-scope.js +2 -2
- package/dist/modules/query_index/lib/subscriber-scope.js.map +2 -2
- package/dist/modules/query_index/subscribers/delete_one.js +3 -2
- package/dist/modules/query_index/subscribers/delete_one.js.map +2 -2
- package/dist/modules/resources/commands/tag-assignments.js +1 -1
- package/dist/modules/resources/commands/tag-assignments.js.map +2 -2
- package/dist/modules/resources/commands/tags.js +1 -1
- package/dist/modules/resources/commands/tags.js.map +2 -2
- package/dist/modules/resources/data/entities.js +2 -1
- package/dist/modules/resources/data/entities.js.map +2 -2
- package/dist/modules/sales/commands/documentAddresses.js +2 -2
- package/dist/modules/sales/commands/documentAddresses.js.map +2 -2
- package/dist/modules/sales/commands/notes.js.map +2 -2
- package/dist/modules/sales/commands/tags.js +1 -1
- package/dist/modules/sales/commands/tags.js.map +2 -2
- package/dist/modules/sales/data/enrichers.js +9 -8
- package/dist/modules/sales/data/enrichers.js.map +2 -2
- package/dist/modules/sales/data/entities.js +2 -11
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/shipping_carriers/data/entities.js +2 -1
- package/dist/modules/shipping_carriers/data/entities.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/shipping-service.js +1 -1
- package/dist/modules/shipping_carriers/lib/shipping-service.js.map +2 -2
- package/dist/modules/shipping_carriers/lib/webhook-utils.js +2 -2
- package/dist/modules/shipping_carriers/lib/webhook-utils.js.map +2 -2
- package/dist/modules/staff/data/entities.js +1 -1
- package/dist/modules/staff/data/entities.js.map +2 -2
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js +3 -5
- package/dist/modules/translations/api/[entityType]/[entityId]/route.js.map +2 -2
- package/dist/modules/translations/api/context.js +2 -2
- package/dist/modules/translations/api/context.js.map +2 -2
- package/dist/modules/translations/commands/translations.js +46 -39
- package/dist/modules/translations/commands/translations.js.map +2 -2
- package/dist/modules/translations/components/TranslationManager.js +19 -10
- package/dist/modules/translations/components/TranslationManager.js.map +2 -2
- package/dist/modules/translations/data/entities.js +1 -1
- package/dist/modules/translations/data/entities.js.map +2 -2
- package/dist/modules/translations/lib/apply.js +4 -4
- package/dist/modules/translations/lib/apply.js.map +2 -2
- package/dist/modules/translations/lib/batch.js +3 -2
- package/dist/modules/translations/lib/batch.js.map +2 -2
- package/dist/modules/translations/subscribers/cleanup.js +3 -5
- package/dist/modules/translations/subscribers/cleanup.js.map +2 -2
- package/dist/modules/workflows/api/definitions/route.js +1 -1
- package/dist/modules/workflows/api/definitions/route.js.map +2 -2
- package/dist/modules/workflows/cli.js +5 -5
- package/dist/modules/workflows/cli.js.map +2 -2
- package/dist/modules/workflows/data/entities.js +2 -1
- package/dist/modules/workflows/data/entities.js.map +2 -2
- package/dist/modules/workflows/lib/event-logger.js +2 -2
- package/dist/modules/workflows/lib/event-logger.js.map +2 -2
- package/dist/modules/workflows/lib/seeds.js +16 -1
- package/dist/modules/workflows/lib/seeds.js.map +2 -2
- package/dist/modules/workflows/lib/step-handler.js +3 -3
- package/dist/modules/workflows/lib/step-handler.js.map +2 -2
- package/dist/modules/workflows/lib/task-handler.js +1 -1
- package/dist/modules/workflows/lib/task-handler.js.map +2 -2
- package/dist/modules/workflows/lib/transition-handler.js +1 -1
- package/dist/modules/workflows/lib/transition-handler.js.map +2 -2
- package/dist/modules/workflows/lib/workflow-executor.js +2 -2
- package/dist/modules/workflows/lib/workflow-executor.js.map +2 -2
- package/jest.config.cjs +4 -2
- package/package.json +3 -3
- package/src/modules/api_keys/data/entities.ts +1 -1
- package/src/modules/api_keys/services/apiKeyService.ts +5 -5
- package/src/modules/attachments/api/library/[id]/route.ts +1 -1
- package/src/modules/attachments/api/library/route.ts +10 -12
- package/src/modules/attachments/api/partitions/route.ts +3 -3
- package/src/modules/attachments/api/route.ts +10 -8
- package/src/modules/attachments/api/transfer/route.ts +1 -1
- package/src/modules/attachments/data/entities.ts +2 -1
- package/src/modules/attachments/lib/ocrQueue.ts +1 -1
- package/src/modules/audit_logs/api/audit-logs/actions/export/route.ts +4 -4
- package/src/modules/audit_logs/api/audit-logs/actions/route.ts +4 -4
- package/src/modules/audit_logs/data/entities.ts +1 -1
- package/src/modules/audit_logs/services/actionLogService.ts +96 -87
- package/src/modules/auth/api/roles/acl/route.ts +1 -1
- package/src/modules/auth/api/users/acl/route.ts +2 -2
- package/src/modules/auth/api/users/resend-invite/route.ts +1 -1
- package/src/modules/auth/cli.ts +46 -40
- package/src/modules/auth/commands/users.ts +1 -1
- package/src/modules/auth/data/entities.ts +1 -1
- package/src/modules/auth/lib/setup-app.ts +3 -3
- package/src/modules/auth/services/authService.ts +2 -2
- package/src/modules/business_rules/api/rules/route.ts +3 -3
- package/src/modules/business_rules/api/sets/[id]/members/route.ts +7 -4
- package/src/modules/business_rules/api/sets/route.ts +3 -3
- package/src/modules/business_rules/cli.ts +1 -1
- package/src/modules/business_rules/data/entities.ts +2 -9
- package/src/modules/business_rules/lib/rule-engine.ts +1 -1
- package/src/modules/catalog/api/option-schemas/route.ts +0 -1
- package/src/modules/catalog/data/entities.ts +2 -11
- package/src/modules/configs/data/entities.ts +2 -1
- package/src/modules/currencies/commands/fetch-configs.ts +3 -3
- package/src/modules/currencies/data/entities.ts +1 -1
- package/src/modules/customer_accounts/api/signup.ts +1 -1
- package/src/modules/customer_accounts/data/entities.ts +1 -1
- package/src/modules/customer_accounts/services/customerInvitationService.ts +1 -1
- package/src/modules/customer_accounts/services/customerSessionService.ts +1 -1
- package/src/modules/customer_accounts/services/customerTokenService.ts +26 -15
- package/src/modules/customers/api/interactions/conflicts/route.ts +26 -23
- package/src/modules/customers/api/interactions/counts/route.ts +13 -11
- package/src/modules/customers/api/interactions/route.ts +32 -44
- package/src/modules/customers/api/utils.ts +45 -37
- package/src/modules/customers/cli.ts +88 -67
- package/src/modules/customers/commands/dictionaries.ts +1 -1
- package/src/modules/customers/commands/tags.ts +1 -1
- package/src/modules/customers/data/entities.ts +2 -12
- package/src/modules/customers/lib/interactionProjection.ts +36 -25
- package/src/modules/customers/lib/personCompanyLinkTable.ts +13 -18
- package/src/modules/dashboards/api/roles/widgets/route.ts +1 -1
- package/src/modules/dashboards/api/users/widgets/route.ts +1 -1
- package/src/modules/dashboards/data/entities.ts +1 -1
- package/src/modules/data_sync/api/mappings/route.ts +1 -1
- package/src/modules/data_sync/data/entities.ts +2 -1
- package/src/modules/data_sync/lib/id-mapping.ts +1 -1
- package/src/modules/data_sync/lib/sync-run-service.ts +1 -1
- package/src/modules/dictionaries/commands/factory.ts +1 -1
- package/src/modules/dictionaries/data/entities.ts +2 -9
- package/src/modules/directory/commands/organizations.ts +4 -4
- package/src/modules/directory/data/entities.ts +2 -1
- package/src/modules/entities/api/definitions.ts +2 -2
- package/src/modules/entities/api/encryption.ts +2 -2
- package/src/modules/entities/api/relations/options.ts +8 -3
- package/src/modules/entities/cli.ts +4 -4
- package/src/modules/entities/data/entities.ts +1 -1
- package/src/modules/entities/lib/field-definitions.ts +2 -2
- package/src/modules/entities/lib/register.ts +1 -1
- package/src/modules/feature_toggles/data/entities.ts +2 -9
- package/src/modules/inbox_ops/api/proposals/counts/route.ts +10 -10
- package/src/modules/inbox_ops/data/entities.ts +2 -8
- package/src/modules/inbox_ops/lib/messagesIntegration.ts +12 -11
- package/src/modules/integrations/data/entities.ts +2 -1
- package/src/modules/integrations/lib/credentials-service.ts +1 -1
- package/src/modules/integrations/lib/log-service.ts +1 -1
- package/src/modules/integrations/lib/state-service.ts +1 -1
- package/src/modules/messages/api/route.ts +134 -123
- package/src/modules/messages/api/unread-count/route.ts +19 -16
- package/src/modules/messages/commands/confirmations.ts +1 -1
- package/src/modules/messages/commands/messages.ts +3 -3
- package/src/modules/messages/data/entities.ts +2 -1
- package/src/modules/messages/lib/email-sender.ts +1 -1
- package/src/modules/messages/lib/searchLookup.ts +16 -13
- package/src/modules/messages/lib/tokenConsumption.ts +16 -8
- package/src/modules/notifications/data/entities.ts +2 -1
- package/src/modules/notifications/lib/notificationRecipients.ts +42 -26
- package/src/modules/notifications/lib/notificationService.ts +53 -42
- package/src/modules/notifications/workers/create-notification.worker.ts +20 -17
- package/src/modules/payment_gateways/api/transactions/route.ts +2 -2
- package/src/modules/payment_gateways/data/entities.ts +2 -1
- package/src/modules/payment_gateways/lib/gateway-service.ts +1 -1
- package/src/modules/payment_gateways/lib/webhook-utils.ts +2 -2
- package/src/modules/perspectives/data/entities.ts +1 -1
- package/src/modules/planner/data/entities.ts +1 -1
- package/src/modules/progress/data/entities.ts +2 -1
- package/src/modules/progress/lib/progressServiceImpl.ts +1 -1
- package/src/modules/query_index/api/status.ts +85 -71
- package/src/modules/query_index/cli.ts +51 -31
- package/src/modules/query_index/data/entities.ts +1 -1
- package/src/modules/query_index/di.ts +41 -16
- package/src/modules/query_index/lib/batch.ts +68 -55
- package/src/modules/query_index/lib/coverage.ts +115 -88
- package/src/modules/query_index/lib/engine.ts +1036 -1096
- package/src/modules/query_index/lib/indexer.ts +115 -79
- package/src/modules/query_index/lib/jobs.ts +51 -31
- package/src/modules/query_index/lib/purge.ts +25 -19
- package/src/modules/query_index/lib/reindexer.ts +97 -84
- package/src/modules/query_index/lib/search-tokens.ts +67 -36
- package/src/modules/query_index/lib/stale.ts +14 -17
- package/src/modules/query_index/lib/subscriber-scope.ts +6 -5
- package/src/modules/query_index/subscribers/delete_one.ts +9 -6
- package/src/modules/resources/commands/tag-assignments.ts +1 -1
- package/src/modules/resources/commands/tags.ts +1 -1
- package/src/modules/resources/data/entities.ts +2 -1
- package/src/modules/sales/commands/documentAddresses.ts +2 -2
- package/src/modules/sales/commands/notes.ts +1 -1
- package/src/modules/sales/commands/tags.ts +1 -1
- package/src/modules/sales/data/enrichers.ts +17 -13
- package/src/modules/sales/data/entities.ts +2 -11
- package/src/modules/shipping_carriers/data/entities.ts +2 -1
- package/src/modules/shipping_carriers/lib/shipping-service.ts +1 -1
- package/src/modules/shipping_carriers/lib/webhook-utils.ts +2 -2
- package/src/modules/staff/data/entities.ts +1 -1
- package/src/modules/translations/api/[entityType]/[entityId]/route.ts +14 -11
- package/src/modules/translations/api/context.ts +4 -4
- package/src/modules/translations/commands/translations.ts +116 -81
- package/src/modules/translations/components/TranslationManager.tsx +23 -14
- package/src/modules/translations/data/entities.ts +1 -1
- package/src/modules/translations/i18n/de.json +1 -0
- package/src/modules/translations/i18n/en.json +1 -0
- package/src/modules/translations/i18n/es.json +1 -0
- package/src/modules/translations/i18n/pl.json +1 -0
- package/src/modules/translations/lib/apply.ts +6 -6
- package/src/modules/translations/lib/batch.ts +9 -7
- package/src/modules/translations/subscribers/cleanup.ts +10 -11
- package/src/modules/workflows/api/definitions/route.ts +1 -1
- package/src/modules/workflows/cli.ts +5 -5
- package/src/modules/workflows/data/entities.ts +2 -1
- package/src/modules/workflows/lib/event-logger.ts +2 -2
- package/src/modules/workflows/lib/seeds.ts +16 -1
- package/src/modules/workflows/lib/step-handler.ts +3 -3
- package/src/modules/workflows/lib/task-handler.ts +1 -1
- package/src/modules/workflows/lib/transition-handler.ts +1 -1
- package/src/modules/workflows/lib/workflow-executor.ts +2 -2
|
@@ -2,7 +2,7 @@ import type { EntityManager } from '@mikro-orm/postgresql'
|
|
|
2
2
|
import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
|
|
3
3
|
import { resolveTenantEncryptionService } from '@open-mercato/shared/lib/encryption/customFieldValues'
|
|
4
4
|
import { decryptIndexDocForSearch, encryptIndexDocForStorage } from '@open-mercato/shared/lib/encryption/indexDoc'
|
|
5
|
-
import
|
|
5
|
+
import { sql } from 'kysely'
|
|
6
6
|
import { replaceSearchTokensForRecord, deleteSearchTokensForRecord } from './search-tokens'
|
|
7
7
|
import { attachAggregateSearchField } from './document'
|
|
8
8
|
|
|
@@ -14,13 +14,15 @@ type BuildDocParams = {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export async function buildIndexDoc(em: EntityManager, params: BuildDocParams): Promise<Record<string, any> | null> {
|
|
17
|
-
const
|
|
17
|
+
const db = (em as any).getKysely()
|
|
18
18
|
const baseTable = resolveEntityTableName(em, params.entityType)
|
|
19
19
|
|
|
20
20
|
// Fetch base row
|
|
21
|
-
const baseRow = await
|
|
22
|
-
.
|
|
23
|
-
.
|
|
21
|
+
const baseRow = await db
|
|
22
|
+
.selectFrom(baseTable as any)
|
|
23
|
+
.selectAll()
|
|
24
|
+
.where('id' as any, '=', params.recordId)
|
|
25
|
+
.executeTakeFirst() as Record<string, any> | undefined
|
|
24
26
|
if (!baseRow) return null
|
|
25
27
|
const docSources: Array<Record<string, any>> = []
|
|
26
28
|
|
|
@@ -29,15 +31,18 @@ export async function buildIndexDoc(em: EntityManager, params: BuildDocParams):
|
|
|
29
31
|
if (params.entityType === 'customers:customer_person_profile' || params.entityType === 'customers:customer_company_profile') {
|
|
30
32
|
const entityId = (baseRow as any).entity_id ?? (baseRow as any).entityId
|
|
31
33
|
if (entityId) {
|
|
32
|
-
const entityRow = await
|
|
33
|
-
.
|
|
34
|
-
.
|
|
34
|
+
const entityRow = await db
|
|
35
|
+
.selectFrom('customer_entities' as any)
|
|
36
|
+
.selectAll()
|
|
37
|
+
.where('id' as any, '=', entityId)
|
|
38
|
+
.executeTakeFirst() as Record<string, any> | undefined
|
|
35
39
|
if (entityRow) {
|
|
36
40
|
docSources.push(entityRow)
|
|
37
41
|
parentEntityRow = entityRow
|
|
38
42
|
}
|
|
39
43
|
}
|
|
40
44
|
}
|
|
45
|
+
void parentEntityRow
|
|
41
46
|
|
|
42
47
|
// Build base document (snake_case keys as in DB)
|
|
43
48
|
let doc: Record<string, any> = {}
|
|
@@ -47,15 +52,38 @@ export async function buildIndexDoc(em: EntityManager, params: BuildDocParams):
|
|
|
47
52
|
}
|
|
48
53
|
|
|
49
54
|
// Attach custom fields under flat keys 'cf:<key>'
|
|
50
|
-
|
|
51
|
-
.
|
|
52
|
-
.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
let cfQuery = db
|
|
56
|
+
.selectFrom('custom_field_values' as any)
|
|
57
|
+
.select([
|
|
58
|
+
'field_key' as any,
|
|
59
|
+
'value_text' as any,
|
|
60
|
+
'value_multiline' as any,
|
|
61
|
+
'value_int' as any,
|
|
62
|
+
'value_float' as any,
|
|
63
|
+
'value_bool' as any,
|
|
64
|
+
])
|
|
65
|
+
.where('entity_id' as any, '=', params.entityType)
|
|
66
|
+
.where('record_id' as any, '=', String(params.recordId))
|
|
67
|
+
|
|
68
|
+
if (params.organizationId != null) {
|
|
69
|
+
cfQuery = cfQuery.where((eb: any) => eb.or([
|
|
70
|
+
eb('organization_id' as any, '=', params.organizationId),
|
|
71
|
+
eb('organization_id' as any, 'is', null),
|
|
72
|
+
]))
|
|
73
|
+
} else {
|
|
74
|
+
cfQuery = cfQuery.where('organization_id' as any, 'is', null)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (params.tenantId != null) {
|
|
78
|
+
cfQuery = cfQuery.where((eb: any) => eb.or([
|
|
79
|
+
eb('tenant_id' as any, '=', params.tenantId),
|
|
80
|
+
eb('tenant_id' as any, 'is', null),
|
|
81
|
+
]))
|
|
82
|
+
} else {
|
|
83
|
+
cfQuery = cfQuery.where('tenant_id' as any, 'is', null)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const cfRows = await cfQuery.execute() as Array<Record<string, any>>
|
|
59
87
|
|
|
60
88
|
const cfMap: Record<string, any[]> = {}
|
|
61
89
|
for (const r of cfRows) {
|
|
@@ -72,12 +100,14 @@ export async function buildIndexDoc(em: EntityManager, params: BuildDocParams):
|
|
|
72
100
|
|
|
73
101
|
// Attach translations under flat keys 'l10n:{locale}:{field}'
|
|
74
102
|
try {
|
|
75
|
-
const translationRow = await
|
|
76
|
-
.
|
|
77
|
-
.
|
|
78
|
-
.
|
|
79
|
-
.
|
|
80
|
-
.
|
|
103
|
+
const translationRow = await db
|
|
104
|
+
.selectFrom('entity_translations' as any)
|
|
105
|
+
.select(['translations' as any])
|
|
106
|
+
.where('entity_type' as any, '=', params.entityType)
|
|
107
|
+
.where('entity_id' as any, '=', String(params.recordId))
|
|
108
|
+
.where(sql`tenant_id is not distinct from ${params.tenantId ?? null}`)
|
|
109
|
+
.where(sql`organization_id is not distinct from ${params.organizationId ?? null}`)
|
|
110
|
+
.executeTakeFirst() as { translations: Record<string, Record<string, unknown>> | null } | undefined
|
|
81
111
|
|
|
82
112
|
if (translationRow?.translations && typeof translationRow.translations === 'object') {
|
|
83
113
|
for (const [locale, fields] of Object.entries(translationRow.translations)) {
|
|
@@ -113,29 +143,37 @@ export type UpsertIndexResult = {
|
|
|
113
143
|
revived: boolean
|
|
114
144
|
}
|
|
115
145
|
|
|
146
|
+
function scopeEntityIndexes<QB extends { where: (...args: any[]) => QB }>(
|
|
147
|
+
q: QB,
|
|
148
|
+
args: { entityType: string; recordId: string; organizationId?: string | null; tenantId?: string | null },
|
|
149
|
+
): QB {
|
|
150
|
+
let chain = q.where('entity_type' as any, '=', args.entityType)
|
|
151
|
+
chain = chain.where('entity_id' as any, '=', String(args.recordId))
|
|
152
|
+
chain = args.organizationId == null
|
|
153
|
+
? chain.where('organization_id' as any, 'is', null as any)
|
|
154
|
+
: chain.where('organization_id' as any, '=', args.organizationId)
|
|
155
|
+
chain = chain.where(sql`tenant_id is not distinct from ${args.tenantId ?? null}`)
|
|
156
|
+
return chain
|
|
157
|
+
}
|
|
158
|
+
|
|
116
159
|
export async function upsertIndexRow(
|
|
117
160
|
em: EntityManager,
|
|
118
161
|
args: { entityType: string; recordId: string; organizationId?: string | null; tenantId?: string | null }
|
|
119
162
|
): Promise<UpsertIndexResult> {
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
.
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
organization_id: args.organizationId ?? null,
|
|
127
|
-
})
|
|
128
|
-
.andWhereRaw('tenant_id is not distinct from ?', [args.tenantId ?? null])
|
|
129
|
-
.first<{ id: string; deleted_at: Date | null } | undefined>()
|
|
163
|
+
const db = (em as any).getKysely()
|
|
164
|
+
|
|
165
|
+
const existing = await scopeEntityIndexes(
|
|
166
|
+
db.selectFrom('entity_indexes' as any).select(['id' as any, 'deleted_at' as any]),
|
|
167
|
+
args,
|
|
168
|
+
).executeTakeFirst() as { id: string; deleted_at: Date | null } | undefined
|
|
130
169
|
|
|
131
|
-
const existing = await baseScopeQuery
|
|
132
170
|
const existed = !!existing
|
|
133
171
|
const wasDeleted = !!existing && existing.deleted_at != null
|
|
134
172
|
|
|
135
173
|
const doc = await buildIndexDoc(em, args)
|
|
136
174
|
if (!doc) {
|
|
137
175
|
try {
|
|
138
|
-
await deleteSearchTokensForRecord(
|
|
176
|
+
await deleteSearchTokensForRecord(db, {
|
|
139
177
|
entityType: args.entityType,
|
|
140
178
|
recordId: args.recordId,
|
|
141
179
|
organizationId: args.organizationId ?? null,
|
|
@@ -143,14 +181,10 @@ export async function upsertIndexRow(
|
|
|
143
181
|
})
|
|
144
182
|
} catch {}
|
|
145
183
|
if (existed) {
|
|
146
|
-
await
|
|
147
|
-
.
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
organization_id: args.organizationId ?? null,
|
|
151
|
-
})
|
|
152
|
-
.andWhereRaw('tenant_id is not distinct from ?', [args.tenantId ?? null])
|
|
153
|
-
.del()
|
|
184
|
+
await scopeEntityIndexes(
|
|
185
|
+
db.deleteFrom('entity_indexes' as any) as any,
|
|
186
|
+
args,
|
|
187
|
+
).execute()
|
|
154
188
|
}
|
|
155
189
|
return { doc: null, existed, wasDeleted, created: false, revived: false }
|
|
156
190
|
}
|
|
@@ -160,29 +194,40 @@ export async function upsertIndexRow(
|
|
|
160
194
|
entity_id: String(args.recordId),
|
|
161
195
|
organization_id: args.organizationId ?? null,
|
|
162
196
|
tenant_id: args.tenantId ?? null,
|
|
163
|
-
doc
|
|
197
|
+
doc: sql`${JSON.stringify(doc)}::jsonb`,
|
|
164
198
|
index_version: 1,
|
|
165
|
-
updated_at:
|
|
199
|
+
updated_at: sql`now()`,
|
|
166
200
|
deleted_at: null,
|
|
167
201
|
}
|
|
202
|
+
|
|
168
203
|
// Prefer modern upsert keyed by coalesced org id when available; fallback to update-then-insert
|
|
169
204
|
try {
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
.
|
|
173
|
-
.
|
|
205
|
+
await db
|
|
206
|
+
.insertInto('entity_indexes' as any)
|
|
207
|
+
.values({ ...payload, created_at: sql`now()` } as any)
|
|
208
|
+
.onConflict((oc: any) => oc
|
|
209
|
+
.columns(['entity_type', 'entity_id', 'organization_id_coalesced'])
|
|
210
|
+
.doUpdateSet({
|
|
211
|
+
tenant_id: args.tenantId ?? null,
|
|
212
|
+
doc: sql`${JSON.stringify(doc)}::jsonb`,
|
|
213
|
+
index_version: 1,
|
|
214
|
+
updated_at: sql`now()`,
|
|
215
|
+
deleted_at: null,
|
|
216
|
+
} as any))
|
|
217
|
+
.execute()
|
|
174
218
|
} catch {
|
|
175
219
|
// Fallback for schemas without organization_id_coalesced column/index
|
|
176
|
-
const updated = await
|
|
177
|
-
.
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
220
|
+
const updated = await scopeEntityIndexes(
|
|
221
|
+
db.updateTable('entity_indexes' as any).set(payload as any) as any,
|
|
222
|
+
args,
|
|
223
|
+
).executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
|
|
224
|
+
if (!updated || Number(updated.numUpdatedRows ?? 0) === 0) {
|
|
225
|
+
try {
|
|
226
|
+
await db
|
|
227
|
+
.insertInto('entity_indexes' as any)
|
|
228
|
+
.values({ ...payload, created_at: sql`now()` } as any)
|
|
229
|
+
.execute()
|
|
230
|
+
} catch {}
|
|
186
231
|
}
|
|
187
232
|
}
|
|
188
233
|
|
|
@@ -198,7 +243,7 @@ export async function upsertIndexRow(
|
|
|
198
243
|
encryption,
|
|
199
244
|
dekKeyCache,
|
|
200
245
|
)
|
|
201
|
-
await replaceSearchTokensForRecord(
|
|
246
|
+
await replaceSearchTokensForRecord(db, {
|
|
202
247
|
entityType: args.entityType,
|
|
203
248
|
recordId: args.recordId,
|
|
204
249
|
organizationId: args.organizationId ?? null,
|
|
@@ -213,36 +258,27 @@ export async function markDeleted(
|
|
|
213
258
|
em: EntityManager,
|
|
214
259
|
args: { entityType: string; recordId: string; organizationId?: string | null; tenantId?: string | null }
|
|
215
260
|
): Promise<{ wasActive: boolean }> {
|
|
216
|
-
const
|
|
217
|
-
const existing = await
|
|
218
|
-
.select(['deleted_at'])
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
entity_id: String(args.recordId),
|
|
222
|
-
organization_id: args.organizationId ?? null,
|
|
223
|
-
})
|
|
224
|
-
.andWhereRaw('tenant_id is not distinct from ?', [args.tenantId ?? null])
|
|
225
|
-
.first<{ deleted_at: Date | null } | undefined>()
|
|
261
|
+
const db = (em as any).getKysely()
|
|
262
|
+
const existing = await scopeEntityIndexes(
|
|
263
|
+
db.selectFrom('entity_indexes' as any).select(['deleted_at' as any]),
|
|
264
|
+
args,
|
|
265
|
+
).executeTakeFirst() as { deleted_at: Date | null } | undefined
|
|
226
266
|
|
|
227
267
|
const wasActive = !!existing && existing.deleted_at == null
|
|
228
268
|
|
|
229
269
|
if (existing) {
|
|
230
270
|
try {
|
|
231
|
-
await deleteSearchTokensForRecord(
|
|
271
|
+
await deleteSearchTokensForRecord(db, {
|
|
232
272
|
entityType: args.entityType,
|
|
233
273
|
recordId: args.recordId,
|
|
234
274
|
organizationId: args.organizationId ?? null,
|
|
235
275
|
tenantId: args.tenantId ?? null,
|
|
236
276
|
})
|
|
237
277
|
} catch {}
|
|
238
|
-
await
|
|
239
|
-
.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
organization_id: args.organizationId ?? null,
|
|
243
|
-
})
|
|
244
|
-
.andWhereRaw('tenant_id is not distinct from ?', [args.tenantId ?? null])
|
|
245
|
-
.del()
|
|
278
|
+
await scopeEntityIndexes(
|
|
279
|
+
db.deleteFrom('entity_indexes' as any) as any,
|
|
280
|
+
args,
|
|
281
|
+
).execute()
|
|
246
282
|
}
|
|
247
283
|
|
|
248
284
|
return { wasActive }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Kysely, sql } from 'kysely'
|
|
2
2
|
|
|
3
3
|
export type JobScope = {
|
|
4
4
|
entityType: string
|
|
@@ -8,65 +8,85 @@ export type JobScope = {
|
|
|
8
8
|
partitionCount?: number | null
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
function applyScopeWhere<QB extends { where: (...args: any[]) => QB }>(
|
|
12
|
+
builder: QB,
|
|
13
|
+
scope: JobScope,
|
|
14
|
+
): QB {
|
|
15
|
+
let q = builder.where('entity_type' as any, '=', scope.entityType)
|
|
16
|
+
q = q.where(sql`organization_id is not distinct from ${scope.organizationId ?? null}`)
|
|
17
|
+
q = q.where(sql`tenant_id is not distinct from ${scope.tenantId ?? null}`)
|
|
18
|
+
q = q.where(sql`partition_index is not distinct from ${scope.partitionIndex ?? null}`)
|
|
19
|
+
q = q.where(sql`partition_count is not distinct from ${scope.partitionCount ?? null}`)
|
|
20
|
+
return q
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
export async function prepareJob(
|
|
21
|
-
|
|
24
|
+
db: Kysely<any>,
|
|
22
25
|
scope: JobScope,
|
|
23
26
|
status: 'reindexing' | 'purging',
|
|
24
27
|
options: { totalCount?: number | null } = {},
|
|
25
|
-
) {
|
|
28
|
+
): Promise<string | null> {
|
|
26
29
|
const base = {
|
|
27
30
|
organization_id: scope.organizationId ?? null,
|
|
28
31
|
tenant_id: scope.tenantId ?? null,
|
|
29
32
|
partition_index: scope.partitionIndex ?? null,
|
|
30
33
|
partition_count: scope.partitionCount ?? null,
|
|
31
34
|
status,
|
|
32
|
-
started_at:
|
|
35
|
+
started_at: sql`now()`,
|
|
33
36
|
finished_at: null,
|
|
34
|
-
heartbeat_at:
|
|
37
|
+
heartbeat_at: sql`now()`,
|
|
35
38
|
processed_count: 0,
|
|
36
39
|
total_count: options.totalCount ?? null,
|
|
37
40
|
}
|
|
38
|
-
|
|
41
|
+
|
|
42
|
+
const existing = await applyScopeWhere(
|
|
43
|
+
db.selectFrom('entity_index_jobs' as any).select(['id' as any]),
|
|
44
|
+
scope,
|
|
45
|
+
).executeTakeFirst() as { id: string } | undefined
|
|
46
|
+
|
|
39
47
|
if (existing) {
|
|
40
|
-
await
|
|
48
|
+
await applyScopeWhere(
|
|
49
|
+
db.updateTable('entity_index_jobs' as any).set(base as any) as any,
|
|
50
|
+
scope,
|
|
51
|
+
).execute()
|
|
41
52
|
return existing.id
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
|
|
54
|
+
|
|
55
|
+
const inserted = await db
|
|
56
|
+
.insertInto('entity_index_jobs' as any)
|
|
57
|
+
.values({
|
|
45
58
|
entity_type: scope.entityType,
|
|
46
59
|
...base,
|
|
47
|
-
})
|
|
48
|
-
.returning
|
|
60
|
+
} as any)
|
|
61
|
+
.returning(['id' as any])
|
|
62
|
+
.execute() as Array<{ id: string }>
|
|
63
|
+
|
|
49
64
|
return inserted?.[0]?.id ?? null
|
|
50
65
|
}
|
|
51
66
|
|
|
52
67
|
export async function updateJobProgress(
|
|
53
|
-
|
|
68
|
+
db: Kysely<any>,
|
|
54
69
|
scope: JobScope,
|
|
55
70
|
processedDelta: number,
|
|
56
|
-
) {
|
|
57
|
-
await
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
71
|
+
): Promise<void> {
|
|
72
|
+
await applyScopeWhere(
|
|
73
|
+
db.updateTable('entity_index_jobs' as any).set({
|
|
74
|
+
processed_count: sql`coalesce(processed_count, 0) + ${Math.max(0, processedDelta)}`,
|
|
75
|
+
heartbeat_at: sql`now()`,
|
|
76
|
+
} as any) as any,
|
|
77
|
+
scope,
|
|
78
|
+
).execute()
|
|
61
79
|
}
|
|
62
80
|
|
|
63
81
|
export async function finalizeJob(
|
|
64
|
-
|
|
82
|
+
db: Kysely<any>,
|
|
65
83
|
scope: JobScope,
|
|
66
|
-
) {
|
|
67
|
-
await
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
84
|
+
): Promise<void> {
|
|
85
|
+
await applyScopeWhere(
|
|
86
|
+
db.updateTable('entity_index_jobs' as any).set({
|
|
87
|
+
finished_at: sql`now()`,
|
|
88
|
+
heartbeat_at: sql`now()`,
|
|
89
|
+
} as any) as any,
|
|
90
|
+
scope,
|
|
91
|
+
).execute()
|
|
71
92
|
}
|
|
72
|
-
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
-
import
|
|
2
|
+
import { sql } from 'kysely'
|
|
3
3
|
import { prepareJob, updateJobProgress, finalizeJob, type JobScope } from './jobs'
|
|
4
4
|
|
|
5
5
|
export type PurgeOptions = {
|
|
@@ -12,7 +12,7 @@ export async function purgeIndexScope(
|
|
|
12
12
|
em: EntityManager,
|
|
13
13
|
options: PurgeOptions,
|
|
14
14
|
): Promise<void> {
|
|
15
|
-
const
|
|
15
|
+
const db = em.getKysely<any>()
|
|
16
16
|
const scope: JobScope = {
|
|
17
17
|
entityType: options.entityType,
|
|
18
18
|
organizationId: options.organizationId ?? null,
|
|
@@ -21,28 +21,34 @@ export async function purgeIndexScope(
|
|
|
21
21
|
partitionCount: null,
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const
|
|
25
|
-
.where(
|
|
26
|
-
.
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const totalRow = await
|
|
24
|
+
const applyScope = <QB extends { where: (...args: any[]) => QB }>(q: QB): QB => {
|
|
25
|
+
let chain = q.where('entity_type' as any, '=', options.entityType)
|
|
26
|
+
if (options.organizationId !== undefined) {
|
|
27
|
+
chain = chain.where(sql`organization_id is not distinct from ${options.organizationId ?? null}`)
|
|
28
|
+
}
|
|
29
|
+
if (options.tenantId !== undefined) {
|
|
30
|
+
chain = chain.where(sql`tenant_id is not distinct from ${options.tenantId ?? null}`)
|
|
31
|
+
}
|
|
32
|
+
return chain
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const totalRow = await applyScope(
|
|
36
|
+
db.selectFrom('entity_indexes' as any).select(sql`count(*)`.as('count')),
|
|
37
|
+
).executeTakeFirst() as { count: unknown } | undefined
|
|
38
|
+
|
|
36
39
|
const total = totalRow ? Number(totalRow.count) || 0 : 0
|
|
37
40
|
|
|
38
|
-
await prepareJob(
|
|
41
|
+
await prepareJob(db, scope, 'purging', { totalCount: total })
|
|
39
42
|
|
|
40
43
|
if (total > 0) {
|
|
41
|
-
const
|
|
42
|
-
|
|
44
|
+
const result = await applyScope(
|
|
45
|
+
db.deleteFrom('entity_indexes' as any) as any,
|
|
46
|
+
).executeTakeFirst() as { numDeletedRows?: bigint | number } | undefined
|
|
47
|
+
const removed = Number(result?.numDeletedRows ?? 0)
|
|
48
|
+
await updateJobProgress(db, scope, removed || total)
|
|
43
49
|
} else {
|
|
44
|
-
await updateJobProgress(
|
|
50
|
+
await updateJobProgress(db, scope, 0)
|
|
45
51
|
}
|
|
46
52
|
|
|
47
|
-
await finalizeJob(
|
|
53
|
+
await finalizeJob(db, scope)
|
|
48
54
|
}
|