@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.
- 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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Kysely, sql } from 'kysely'
|
|
2
2
|
import { buildIndexDocument, type IndexCustomFieldValue } from './document'
|
|
3
3
|
import { replaceSearchTokensForBatch, isSearchDebugEnabled } from './search-tokens'
|
|
4
4
|
|
|
@@ -45,7 +45,7 @@ function normalizeScopedValue(value: unknown): string | null {
|
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
export async function upsertIndexBatch(
|
|
48
|
-
|
|
48
|
+
db: Kysely<any>,
|
|
49
49
|
entityType: string,
|
|
50
50
|
rows: AnyRow[],
|
|
51
51
|
scope: ScopeOverrides,
|
|
@@ -68,25 +68,31 @@ export async function upsertIndexBatch(
|
|
|
68
68
|
),
|
|
69
69
|
)
|
|
70
70
|
if (entityIds.length) {
|
|
71
|
-
const entityRows = await
|
|
71
|
+
const entityRows = await db
|
|
72
|
+
.selectFrom('customer_entities' as any)
|
|
73
|
+
.selectAll()
|
|
74
|
+
.where('id' as any, 'in', entityIds)
|
|
75
|
+
.execute() as AnyRow[]
|
|
72
76
|
customerEntitiesById = new Map(entityRows.map((row) => [normalizeId(row.id), row]))
|
|
73
77
|
}
|
|
74
78
|
}
|
|
75
79
|
|
|
76
|
-
const customFieldRows = await
|
|
80
|
+
const customFieldRows = await db
|
|
81
|
+
.selectFrom('custom_field_values' as any)
|
|
77
82
|
.select([
|
|
78
|
-
'record_id',
|
|
79
|
-
'field_key',
|
|
80
|
-
'value_text',
|
|
81
|
-
'value_multiline',
|
|
82
|
-
'value_int',
|
|
83
|
-
'value_float',
|
|
84
|
-
'value_bool',
|
|
85
|
-
'organization_id',
|
|
86
|
-
'tenant_id',
|
|
83
|
+
'record_id' as any,
|
|
84
|
+
'field_key' as any,
|
|
85
|
+
'value_text' as any,
|
|
86
|
+
'value_multiline' as any,
|
|
87
|
+
'value_int' as any,
|
|
88
|
+
'value_float' as any,
|
|
89
|
+
'value_bool' as any,
|
|
90
|
+
'organization_id' as any,
|
|
91
|
+
'tenant_id' as any,
|
|
87
92
|
])
|
|
88
|
-
.where('entity_id', entityType)
|
|
89
|
-
.
|
|
93
|
+
.where('entity_id' as any, '=', entityType)
|
|
94
|
+
.where('record_id' as any, 'in', recordIds)
|
|
95
|
+
.execute() as CustomFieldRow[]
|
|
90
96
|
|
|
91
97
|
const customFieldMap = new Map<string, CustomFieldRow[]>()
|
|
92
98
|
for (const fieldRow of customFieldRows) {
|
|
@@ -207,10 +213,10 @@ export async function upsertIndexBatch(
|
|
|
207
213
|
entity_id: payload.entity_id,
|
|
208
214
|
organization_id: payload.organization_id,
|
|
209
215
|
tenant_id: payload.tenant_id,
|
|
210
|
-
doc: payload.doc
|
|
216
|
+
doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
|
|
211
217
|
index_version: payload.index_version,
|
|
212
|
-
created_at:
|
|
213
|
-
updated_at:
|
|
218
|
+
created_at: sql`now()`,
|
|
219
|
+
updated_at: sql`now()`,
|
|
214
220
|
deleted_at: null,
|
|
215
221
|
}))
|
|
216
222
|
|
|
@@ -223,19 +229,22 @@ export async function upsertIndexBatch(
|
|
|
223
229
|
}))
|
|
224
230
|
|
|
225
231
|
try {
|
|
226
|
-
await
|
|
227
|
-
.
|
|
228
|
-
.
|
|
229
|
-
.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
232
|
+
await db
|
|
233
|
+
.insertInto('entity_indexes' as any)
|
|
234
|
+
.values(insertRows as any)
|
|
235
|
+
.onConflict((oc: any) => oc
|
|
236
|
+
.columns(['entity_type', 'entity_id', 'organization_id_coalesced'])
|
|
237
|
+
.doUpdateSet({
|
|
238
|
+
doc: sql`excluded.doc`,
|
|
239
|
+
index_version: sql`excluded.index_version`,
|
|
240
|
+
organization_id: sql`excluded.organization_id`,
|
|
241
|
+
tenant_id: sql`excluded.tenant_id`,
|
|
242
|
+
deleted_at: sql`excluded.deleted_at`,
|
|
243
|
+
updated_at: sql`now()`,
|
|
244
|
+
} as any))
|
|
245
|
+
.execute()
|
|
237
246
|
try {
|
|
238
|
-
await replaceSearchTokensForBatch(
|
|
247
|
+
await replaceSearchTokensForBatch(db, tokenPayloads)
|
|
239
248
|
} catch {}
|
|
240
249
|
if (debugEnabled) {
|
|
241
250
|
console.info('[reindex:batch:tokens]', {
|
|
@@ -247,36 +256,40 @@ export async function upsertIndexBatch(
|
|
|
247
256
|
}
|
|
248
257
|
return
|
|
249
258
|
} catch {
|
|
250
|
-
await
|
|
251
|
-
const now = trx.fn.now()
|
|
259
|
+
await db.transaction().execute(async (trx) => {
|
|
252
260
|
for (const payload of basePayloads) {
|
|
253
|
-
|
|
254
|
-
.
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
organization_id: payload.organization_id ?? null,
|
|
258
|
-
})
|
|
259
|
-
.update({
|
|
260
|
-
doc: payload.doc,
|
|
261
|
+
let updateQuery = trx
|
|
262
|
+
.updateTable('entity_indexes' as any)
|
|
263
|
+
.set({
|
|
264
|
+
doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
|
|
261
265
|
index_version: payload.index_version,
|
|
262
266
|
organization_id: payload.organization_id ?? null,
|
|
263
267
|
tenant_id: payload.tenant_id ?? null,
|
|
264
|
-
updated_at: now
|
|
268
|
+
updated_at: sql`now()`,
|
|
265
269
|
deleted_at: null,
|
|
266
|
-
})
|
|
267
|
-
|
|
270
|
+
} as any)
|
|
271
|
+
.where('entity_type' as any, '=', payload.entity_type)
|
|
272
|
+
.where('entity_id' as any, '=', payload.entity_id)
|
|
273
|
+
updateQuery = payload.organization_id == null
|
|
274
|
+
? updateQuery.where('organization_id' as any, 'is', null as any)
|
|
275
|
+
: updateQuery.where('organization_id' as any, '=', payload.organization_id)
|
|
276
|
+
const result = await updateQuery.executeTakeFirst() as { numUpdatedRows?: bigint | number } | undefined
|
|
277
|
+
if (result && Number(result.numUpdatedRows ?? 0) > 0) continue
|
|
268
278
|
try {
|
|
269
|
-
await trx
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
279
|
+
await trx
|
|
280
|
+
.insertInto('entity_indexes' as any)
|
|
281
|
+
.values({
|
|
282
|
+
entity_type: payload.entity_type,
|
|
283
|
+
entity_id: payload.entity_id,
|
|
284
|
+
organization_id: payload.organization_id,
|
|
285
|
+
tenant_id: payload.tenant_id,
|
|
286
|
+
doc: sql`${JSON.stringify(payload.doc)}::jsonb`,
|
|
287
|
+
index_version: payload.index_version,
|
|
288
|
+
created_at: sql`now()`,
|
|
289
|
+
updated_at: sql`now()`,
|
|
290
|
+
deleted_at: null,
|
|
291
|
+
} as any)
|
|
292
|
+
.execute()
|
|
280
293
|
} catch {
|
|
281
294
|
// ignore duplicate insert race; another concurrent worker updated the row
|
|
282
295
|
}
|
|
@@ -284,6 +297,6 @@ export async function upsertIndexBatch(
|
|
|
284
297
|
})
|
|
285
298
|
}
|
|
286
299
|
try {
|
|
287
|
-
await replaceSearchTokensForBatch(
|
|
300
|
+
await replaceSearchTokensForBatch(db, tokenPayloads)
|
|
288
301
|
} catch {}
|
|
289
302
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { EntityManager } from '@mikro-orm/postgresql'
|
|
2
|
-
import type
|
|
2
|
+
import { type Kysely, sql } from 'kysely'
|
|
3
3
|
import { resolveEntityTableName } from '@open-mercato/shared/lib/query/engine'
|
|
4
4
|
|
|
5
5
|
export type CoverageScope = {
|
|
@@ -57,71 +57,86 @@ function normalizeOrganizationForStore(orgId: string | null | undefined): string
|
|
|
57
57
|
return orgId ?? GLOBAL_ORGANIZATION_PLACEHOLDER
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
-
function applyOrganizationCondition(
|
|
61
|
-
qb:
|
|
60
|
+
function applyOrganizationCondition<QB extends { where: (...args: any[]) => QB }>(
|
|
61
|
+
qb: QB,
|
|
62
62
|
column: string,
|
|
63
|
-
organizationId: string | null | undefined
|
|
64
|
-
) {
|
|
63
|
+
organizationId: string | null | undefined,
|
|
64
|
+
): QB {
|
|
65
65
|
const stored = normalizeOrganizationForStore(organizationId ?? null)
|
|
66
66
|
if (stored === GLOBAL_ORGANIZATION_PLACEHOLDER) {
|
|
67
|
-
qb.
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
qb.andWhere(column, stored)
|
|
67
|
+
return qb.where((eb: any) => eb.or([
|
|
68
|
+
eb(column as any, 'is', null),
|
|
69
|
+
eb(column as any, '=', GLOBAL_ORGANIZATION_PLACEHOLDER),
|
|
70
|
+
]))
|
|
72
71
|
}
|
|
72
|
+
return qb.where(column as any, '=', stored)
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
async function fetchCoverageRow(
|
|
76
|
-
|
|
76
|
+
db: Kysely<any>,
|
|
77
77
|
scope: CoverageScope
|
|
78
78
|
): Promise<(CoverageRow & { organization_id: string | null }) | null> {
|
|
79
79
|
const { entityType, tenantId, organizationId, withDeleted } = scope
|
|
80
|
-
|
|
81
|
-
.
|
|
82
|
-
.
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
let query = db
|
|
81
|
+
.selectFrom('entity_index_coverage' as any)
|
|
82
|
+
.select([
|
|
83
|
+
'base_count' as any,
|
|
84
|
+
'indexed_count' as any,
|
|
85
|
+
'vector_indexed_count' as any,
|
|
86
|
+
'refreshed_at' as any,
|
|
87
|
+
'organization_id' as any,
|
|
88
|
+
])
|
|
89
|
+
.where('entity_type' as any, '=', entityType)
|
|
90
|
+
.where('with_deleted' as any, '=', withDeleted === true)
|
|
91
|
+
.orderBy('refreshed_at' as any, 'desc')
|
|
92
|
+
query = tenantId == null
|
|
93
|
+
? query.where('tenant_id' as any, 'is', null as any)
|
|
94
|
+
: query.where('tenant_id' as any, '=', tenantId)
|
|
95
|
+
query = applyOrganizationCondition(query as any, 'organization_id', organizationId ?? null)
|
|
96
|
+
const row = await query.executeTakeFirst() as (CoverageRow & { organization_id: string | null }) | undefined
|
|
88
97
|
return row ?? null
|
|
89
98
|
}
|
|
90
99
|
|
|
91
100
|
async function pruneDuplicateCoverageRows(
|
|
92
|
-
|
|
101
|
+
db: Kysely<any>,
|
|
93
102
|
scope: CoverageScope,
|
|
94
103
|
keepId: string | null
|
|
95
|
-
) {
|
|
96
|
-
|
|
97
|
-
.
|
|
98
|
-
.where('
|
|
99
|
-
.where('with_deleted', scope.withDeleted === true)
|
|
100
|
-
|
|
104
|
+
): Promise<void> {
|
|
105
|
+
let query = db
|
|
106
|
+
.deleteFrom('entity_index_coverage' as any)
|
|
107
|
+
.where('entity_type' as any, '=', scope.entityType)
|
|
108
|
+
.where('with_deleted' as any, '=', scope.withDeleted === true)
|
|
109
|
+
query = scope.tenantId == null
|
|
110
|
+
? query.where('tenant_id' as any, 'is', null as any)
|
|
111
|
+
: query.where('tenant_id' as any, '=', scope.tenantId)
|
|
112
|
+
query = applyOrganizationCondition(query as any, 'organization_id', scope.organizationId ?? null)
|
|
101
113
|
if (keepId) {
|
|
102
|
-
|
|
103
|
-
} else {
|
|
104
|
-
await query.del()
|
|
114
|
+
query = query.where('id' as any, '!=', keepId)
|
|
105
115
|
}
|
|
116
|
+
await query.execute()
|
|
106
117
|
}
|
|
107
118
|
|
|
108
119
|
async function upsertCoverageRow(
|
|
109
|
-
|
|
120
|
+
db: Kysely<any>,
|
|
110
121
|
scope: CoverageScope,
|
|
111
122
|
counts: { baseCount: number; indexedCount: number; vectorIndexedCount: number }
|
|
112
|
-
) {
|
|
123
|
+
): Promise<void> {
|
|
113
124
|
const storedOrgId = normalizeOrganizationForStore(scope.organizationId ?? null)
|
|
114
125
|
if (scope.organizationId == null) {
|
|
115
|
-
|
|
116
|
-
.
|
|
117
|
-
.where('
|
|
118
|
-
.where('with_deleted', scope.withDeleted === true)
|
|
119
|
-
.
|
|
120
|
-
|
|
126
|
+
let purge = db
|
|
127
|
+
.deleteFrom('entity_index_coverage' as any)
|
|
128
|
+
.where('entity_type' as any, '=', scope.entityType)
|
|
129
|
+
.where('with_deleted' as any, '=', scope.withDeleted === true)
|
|
130
|
+
.where('organization_id' as any, 'is', null as any)
|
|
131
|
+
purge = scope.tenantId == null
|
|
132
|
+
? purge.where('tenant_id' as any, 'is', null as any)
|
|
133
|
+
: purge.where('tenant_id' as any, '=', scope.tenantId)
|
|
134
|
+
await purge.execute()
|
|
121
135
|
}
|
|
122
136
|
|
|
123
|
-
const rows = await
|
|
124
|
-
.
|
|
137
|
+
const rows = await db
|
|
138
|
+
.insertInto('entity_index_coverage' as any)
|
|
139
|
+
.values({
|
|
125
140
|
entity_type: scope.entityType,
|
|
126
141
|
tenant_id: scope.tenantId ?? null,
|
|
127
142
|
organization_id: storedOrgId,
|
|
@@ -129,28 +144,30 @@ async function upsertCoverageRow(
|
|
|
129
144
|
base_count: counts.baseCount,
|
|
130
145
|
indexed_count: counts.indexedCount,
|
|
131
146
|
vector_indexed_count: counts.vectorIndexedCount,
|
|
132
|
-
refreshed_at:
|
|
133
|
-
})
|
|
134
|
-
.onConflict(
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
147
|
+
refreshed_at: sql`now()`,
|
|
148
|
+
} as any)
|
|
149
|
+
.onConflict((oc: any) => oc
|
|
150
|
+
.columns(['entity_type', 'tenant_id', 'organization_id', 'with_deleted'])
|
|
151
|
+
.doUpdateSet({
|
|
152
|
+
base_count: counts.baseCount,
|
|
153
|
+
indexed_count: counts.indexedCount,
|
|
154
|
+
vector_indexed_count: counts.vectorIndexedCount,
|
|
155
|
+
refreshed_at: sql`now()`,
|
|
156
|
+
} as any))
|
|
157
|
+
.returning(['id' as any])
|
|
158
|
+
.execute() as Array<{ id: string }>
|
|
142
159
|
|
|
143
160
|
const keepId = rows?.[0]?.id ?? null
|
|
144
|
-
await pruneDuplicateCoverageRows(
|
|
161
|
+
await pruneDuplicateCoverageRows(db, scope, keepId)
|
|
145
162
|
}
|
|
146
163
|
|
|
147
164
|
export async function readCoverageSnapshot(
|
|
148
|
-
|
|
165
|
+
db: Kysely<any>,
|
|
149
166
|
scope: CoverageScope
|
|
150
167
|
): Promise<(CoverageRow & { baseCount: number; indexedCount: number; vectorIndexedCount: number }) | null> {
|
|
151
168
|
const entityType = String(scope.entityType || '')
|
|
152
169
|
if (!entityType) return null
|
|
153
|
-
const row = await fetchCoverageRow(
|
|
170
|
+
const row = await fetchCoverageRow(db, {
|
|
154
171
|
entityType,
|
|
155
172
|
tenantId: scope.tenantId ?? null,
|
|
156
173
|
organizationId: scope.organizationId ?? null,
|
|
@@ -174,11 +191,11 @@ export async function applyCoverageAdjustments(
|
|
|
174
191
|
adjustments: CoverageAdjustment[]
|
|
175
192
|
): Promise<void> {
|
|
176
193
|
if (!adjustments.length) return
|
|
177
|
-
const
|
|
194
|
+
const db = (em as any).getKysely() as Kysely<any>
|
|
178
195
|
const aggregated = aggregateAdjustments(adjustments)
|
|
179
196
|
for (const entry of aggregated) {
|
|
180
197
|
const scope = entry.scope
|
|
181
|
-
const existing = await fetchCoverageRow(
|
|
198
|
+
const existing = await fetchCoverageRow(db, scope)
|
|
182
199
|
const currentBase = existing ? toCount(existing.base_count) : 0
|
|
183
200
|
const currentIndex = existing ? toCount(existing.indexed_count) : 0
|
|
184
201
|
const currentVector = existing ? toCount(existing.vector_indexed_count) : 0
|
|
@@ -186,7 +203,7 @@ export async function applyCoverageAdjustments(
|
|
|
186
203
|
const nextIndex = Math.max(currentIndex + entry.deltaIndex, 0)
|
|
187
204
|
const nextVector = Math.max(currentVector + entry.deltaVector, 0)
|
|
188
205
|
|
|
189
|
-
await upsertCoverageRow(
|
|
206
|
+
await upsertCoverageRow(db, scope, {
|
|
190
207
|
baseCount: nextBase,
|
|
191
208
|
indexedCount: nextIndex,
|
|
192
209
|
vectorIndexedCount: nextVector,
|
|
@@ -194,18 +211,24 @@ export async function applyCoverageAdjustments(
|
|
|
194
211
|
}
|
|
195
212
|
}
|
|
196
213
|
|
|
197
|
-
export async function deleteCoverageForEntity(
|
|
214
|
+
export async function deleteCoverageForEntity(db: Kysely<any>, entityType: string): Promise<void> {
|
|
198
215
|
if (!entityType) return
|
|
199
|
-
await
|
|
216
|
+
await db
|
|
217
|
+
.deleteFrom('entity_index_coverage' as any)
|
|
218
|
+
.where('entity_type' as any, '=', entityType)
|
|
219
|
+
.execute()
|
|
200
220
|
}
|
|
201
221
|
|
|
202
|
-
async function tableHasColumn(
|
|
222
|
+
async function tableHasColumn(db: Kysely<any>, table: string, column: string): Promise<boolean> {
|
|
203
223
|
const key = `${table}.${column}`
|
|
204
224
|
if (COLUMN_CACHE.has(key)) return COLUMN_CACHE.get(key)!
|
|
205
|
-
const exists = await
|
|
206
|
-
.
|
|
207
|
-
.
|
|
208
|
-
.
|
|
225
|
+
const exists = await db
|
|
226
|
+
.selectFrom('information_schema.columns' as any)
|
|
227
|
+
.select(sql<number>`1`.as('present'))
|
|
228
|
+
.where(sql<boolean>`table_schema = current_schema()`)
|
|
229
|
+
.where('table_name' as any, '=', table)
|
|
230
|
+
.where('column_name' as any, '=', column)
|
|
231
|
+
.executeTakeFirst()
|
|
209
232
|
const present = !!exists
|
|
210
233
|
COLUMN_CACHE.set(key, present)
|
|
211
234
|
return present
|
|
@@ -221,47 +244,51 @@ export async function refreshCoverageSnapshot(
|
|
|
221
244
|
const organizationId = scope.organizationId ?? null
|
|
222
245
|
const withDeleted = scope.withDeleted === true
|
|
223
246
|
|
|
224
|
-
const
|
|
247
|
+
const db = (em as any).getKysely() as Kysely<any>
|
|
225
248
|
const baseTable = resolveEntityTableName(em, entityType)
|
|
226
249
|
|
|
227
|
-
const hasOrg = await tableHasColumn(
|
|
228
|
-
const hasTenant = await tableHasColumn(
|
|
229
|
-
const hasDeleted = await tableHasColumn(
|
|
250
|
+
const hasOrg = await tableHasColumn(db, baseTable, 'organization_id')
|
|
251
|
+
const hasTenant = await tableHasColumn(db, baseTable, 'tenant_id')
|
|
252
|
+
const hasDeleted = await tableHasColumn(db, baseTable, 'deleted_at')
|
|
230
253
|
|
|
231
254
|
if (organizationId !== null && !hasOrg) return
|
|
232
255
|
if (tenantId !== null && !hasTenant) return
|
|
233
256
|
|
|
234
|
-
let baseQuery =
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (
|
|
257
|
+
let baseQuery = db
|
|
258
|
+
.selectFrom(`${baseTable} as b` as any)
|
|
259
|
+
.select(sql`count(*)`.as('count'))
|
|
260
|
+
if (organizationId !== null && hasOrg) baseQuery = baseQuery.where('b.organization_id' as any, '=', organizationId)
|
|
261
|
+
if (tenantId !== null && hasTenant) baseQuery = baseQuery.where('b.tenant_id' as any, '=', tenantId)
|
|
262
|
+
if (!withDeleted && hasDeleted) baseQuery = baseQuery.where('b.deleted_at' as any, 'is', null as any)
|
|
238
263
|
|
|
239
|
-
const baseRow = await baseQuery.
|
|
264
|
+
const baseRow = await baseQuery.executeTakeFirst() as { count: unknown } | undefined
|
|
240
265
|
const baseCount = toCount(baseRow?.count)
|
|
241
266
|
|
|
242
|
-
let indexQuery =
|
|
243
|
-
.
|
|
244
|
-
.
|
|
245
|
-
|
|
246
|
-
if (
|
|
247
|
-
if (
|
|
267
|
+
let indexQuery = db
|
|
268
|
+
.selectFrom('entity_indexes as ei' as any)
|
|
269
|
+
.select(sql`count(*)`.as('count'))
|
|
270
|
+
.where('ei.entity_type' as any, '=', entityType)
|
|
271
|
+
if (organizationId !== null) indexQuery = indexQuery.where('ei.organization_id' as any, '=', organizationId)
|
|
272
|
+
if (tenantId !== null) indexQuery = indexQuery.where('ei.tenant_id' as any, '=', tenantId)
|
|
273
|
+
if (!withDeleted) indexQuery = indexQuery.where('ei.deleted_at' as any, 'is', null as any)
|
|
248
274
|
|
|
249
|
-
const indexRow = await indexQuery.
|
|
275
|
+
const indexRow = await indexQuery.executeTakeFirst() as { count: unknown } | undefined
|
|
250
276
|
const indexCount = toCount(indexRow?.count)
|
|
251
277
|
|
|
252
278
|
// Count vector entries directly from database
|
|
253
279
|
let vectorCount: number | undefined
|
|
254
|
-
const hasVectorTable = await tableHasColumn(
|
|
280
|
+
const hasVectorTable = await tableHasColumn(db, 'vector_search', 'entity_id')
|
|
255
281
|
if (hasVectorTable && typeof tenantId === 'string' && tenantId.length > 0) {
|
|
256
282
|
try {
|
|
257
|
-
let vectorQuery =
|
|
258
|
-
.
|
|
259
|
-
.
|
|
260
|
-
.where('
|
|
283
|
+
let vectorQuery = db
|
|
284
|
+
.selectFrom('vector_search' as any)
|
|
285
|
+
.select(sql`count(*)`.as('count'))
|
|
286
|
+
.where('entity_id' as any, '=', entityType)
|
|
287
|
+
.where('tenant_id' as any, '=', tenantId)
|
|
261
288
|
if (organizationId !== null) {
|
|
262
|
-
vectorQuery = vectorQuery.where('organization_id', organizationId)
|
|
289
|
+
vectorQuery = vectorQuery.where('organization_id' as any, '=', organizationId)
|
|
263
290
|
}
|
|
264
|
-
const vectorRow = await vectorQuery.
|
|
291
|
+
const vectorRow = await vectorQuery.executeTakeFirst() as { count: unknown } | undefined
|
|
265
292
|
vectorCount = toCount(vectorRow?.count)
|
|
266
293
|
} catch (err) {
|
|
267
294
|
console.warn('[query_index] Failed to resolve vector count for coverage snapshot', {
|
|
@@ -288,11 +315,11 @@ export async function writeCoverageCounts(
|
|
|
288
315
|
): Promise<void> {
|
|
289
316
|
const entityType = String(scope.entityType || '')
|
|
290
317
|
if (!entityType) return
|
|
291
|
-
const
|
|
318
|
+
const db = (em as any).getKysely() as Kysely<any>
|
|
292
319
|
const tenantId = scope.tenantId ?? null
|
|
293
320
|
const organizationId = scope.organizationId ?? null
|
|
294
321
|
const withDeleted = scope.withDeleted === true
|
|
295
|
-
const existing = await fetchCoverageRow(
|
|
322
|
+
const existing = await fetchCoverageRow(db, {
|
|
296
323
|
entityType,
|
|
297
324
|
tenantId,
|
|
298
325
|
organizationId,
|
|
@@ -307,7 +334,7 @@ export async function writeCoverageCounts(
|
|
|
307
334
|
const vectorCount = counts.vectorCount !== undefined
|
|
308
335
|
? Math.max(0, Math.trunc(toCount(counts.vectorCount)))
|
|
309
336
|
: Math.max(0, Math.trunc(toCount(existing?.vector_indexed_count)))
|
|
310
|
-
await upsertCoverageRow(
|
|
337
|
+
await upsertCoverageRow(db, { entityType, tenantId, organizationId, withDeleted }, {
|
|
311
338
|
baseCount,
|
|
312
339
|
indexedCount: indexCount,
|
|
313
340
|
vectorIndexedCount: vectorCount,
|