@open-mercato/core 0.6.8-develop.7099.1.7ba2771d06 → 0.7.0
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/.turbo/turbo-build.log +1 -1
- package/dist/helpers/integration/api.js +1 -13
- package/dist/helpers/integration/api.js.map +2 -2
- package/dist/helpers/integration/communicationChannelsFixtures.js +0 -19
- package/dist/helpers/integration/communicationChannelsFixtures.js.map +2 -2
- package/dist/modules/api_keys/api/keys/route.js +1 -1
- package/dist/modules/api_keys/api/keys/route.js.map +2 -2
- package/dist/modules/api_keys/backend/api-keys/page.js +1 -3
- package/dist/modules/api_keys/backend/api-keys/page.js.map +2 -2
- package/dist/modules/attachments/api/route.js +2 -2
- package/dist/modules/attachments/api/route.js.map +2 -2
- package/dist/modules/attachments/components/AttachmentLibrary.js +0 -2
- package/dist/modules/attachments/components/AttachmentLibrary.js.map +2 -2
- package/dist/modules/attachments/di.js +1 -11
- package/dist/modules/attachments/di.js.map +2 -2
- package/dist/modules/attachments/index.js.map +1 -1
- package/dist/modules/attachments/lib/scoped-upload-service.js +2 -15
- package/dist/modules/attachments/lib/scoped-upload-service.js.map +2 -2
- package/dist/modules/attachments/lib/upload-limits.js +2 -6
- package/dist/modules/attachments/lib/upload-limits.js.map +2 -2
- package/dist/modules/audit_logs/backend/audit-logs/page.js +0 -6
- package/dist/modules/audit_logs/backend/audit-logs/page.js.map +2 -2
- package/dist/modules/audit_logs/lib/display-helpers.js +11 -19
- package/dist/modules/audit_logs/lib/display-helpers.js.map +2 -2
- package/dist/modules/audit_logs/services/actionLogService.js +12 -57
- package/dist/modules/audit_logs/services/actionLogService.js.map +3 -3
- package/dist/modules/auth/acl.js +5 -30
- package/dist/modules/auth/acl.js.map +2 -2
- package/dist/modules/auth/api/feature-check.js +2 -8
- package/dist/modules/auth/api/feature-check.js.map +2 -2
- package/dist/modules/auth/api/login.js +20 -4
- package/dist/modules/auth/api/login.js.map +2 -2
- package/dist/modules/auth/api/roles/acl/route.js +33 -28
- package/dist/modules/auth/api/roles/acl/route.js.map +2 -2
- package/dist/modules/auth/api/routeError.js +11 -0
- package/dist/modules/auth/api/routeError.js.map +7 -0
- package/dist/modules/auth/api/session/refresh.js +1 -25
- package/dist/modules/auth/api/session/refresh.js.map +2 -2
- package/dist/modules/auth/api/users/acl/route.js +73 -102
- package/dist/modules/auth/api/users/acl/route.js.map +2 -2
- package/dist/modules/auth/backend/roles/[id]/edit/page.meta.js +1 -5
- package/dist/modules/auth/backend/roles/[id]/edit/page.meta.js.map +2 -2
- package/dist/modules/auth/backend/roles/page.js +1 -3
- package/dist/modules/auth/backend/roles/page.js.map +2 -2
- package/dist/modules/auth/backend/users/[id]/edit/page.meta.js +1 -5
- package/dist/modules/auth/backend/users/[id]/edit/page.meta.js.map +2 -2
- package/dist/modules/auth/backend/users/page.js +1 -2
- package/dist/modules/auth/backend/users/page.js.map +2 -2
- package/dist/modules/auth/components/AclEditor.js +30 -39
- package/dist/modules/auth/components/AclEditor.js.map +2 -2
- package/dist/modules/auth/data/entities.js.map +2 -2
- package/dist/modules/auth/data/validators.js +1 -5
- package/dist/modules/auth/data/validators.js.map +2 -2
- package/dist/modules/auth/di.js +9 -35
- package/dist/modules/auth/di.js.map +2 -2
- package/dist/modules/auth/frontend/reset/[token]/page.js +0 -46
- package/dist/modules/auth/frontend/reset/[token]/page.js.map +2 -2
- package/dist/modules/auth/lib/grantChecks.js.map +2 -2
- package/dist/modules/auth/services/authService.js +2 -16
- package/dist/modules/auth/services/authService.js.map +2 -2
- package/dist/modules/auth/services/rbacService.js +24 -67
- package/dist/modules/auth/services/rbacService.js.map +3 -3
- package/dist/modules/business_rules/backend/logs/page.js +1 -3
- package/dist/modules/business_rules/backend/logs/page.js.map +2 -2
- package/dist/modules/business_rules/backend/rules/[id]/page.meta.js +6 -1
- package/dist/modules/business_rules/backend/rules/[id]/page.meta.js.map +2 -2
- package/dist/modules/business_rules/backend/rules/create/page.meta.js +5 -1
- package/dist/modules/business_rules/backend/rules/create/page.meta.js.map +2 -2
- package/dist/modules/business_rules/backend/rules/page.js +1 -3
- package/dist/modules/business_rules/backend/rules/page.js.map +2 -2
- package/dist/modules/business_rules/backend/sets/[id]/page.meta.js +6 -1
- package/dist/modules/business_rules/backend/sets/[id]/page.meta.js.map +2 -2
- package/dist/modules/business_rules/backend/sets/create/page.meta.js +5 -1
- package/dist/modules/business_rules/backend/sets/create/page.meta.js.map +2 -2
- package/dist/modules/business_rules/backend/sets/page.js +1 -3
- package/dist/modules/business_rules/backend/sets/page.js.map +2 -2
- package/dist/modules/business_rules/lib/expression-evaluator.js +9 -9
- package/dist/modules/business_rules/lib/expression-evaluator.js.map +2 -2
- package/dist/modules/business_rules/lib/rule-evaluator.js +9 -10
- package/dist/modules/business_rules/lib/rule-evaluator.js.map +2 -2
- package/dist/modules/catalog/ai-agents.js +1 -1
- package/dist/modules/catalog/ai-agents.js.map +1 -1
- package/dist/modules/catalog/ai-tools/merchandising-pack.js +2 -2
- package/dist/modules/catalog/ai-tools/merchandising-pack.js.map +2 -2
- package/dist/modules/catalog/backend/catalog/products/MerchandisingAssistantSheet.js +2 -5
- package/dist/modules/catalog/backend/catalog/products/MerchandisingAssistantSheet.js.map +2 -2
- package/dist/modules/catalog/components/categories/CategoriesDataTable.js +0 -2
- package/dist/modules/catalog/components/categories/CategoriesDataTable.js.map +2 -2
- package/dist/modules/catalog/components/products/ProductsDataTable.js +1 -7
- package/dist/modules/catalog/components/products/ProductsDataTable.js.map +2 -2
- package/dist/modules/catalog/widgets/injection/merchandising-assistant-trigger/widget.client.js +0 -2
- package/dist/modules/catalog/widgets/injection/merchandising-assistant-trigger/widget.client.js.map +2 -2
- package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js +1 -9
- package/dist/modules/communication_channels/api/post/channels/[id]/test-send/route.js.map +2 -2
- package/dist/modules/communication_channels/api/post/test-seed/route.js +10 -95
- package/dist/modules/communication_channels/api/post/test-seed/route.js.map +2 -2
- package/dist/modules/communication_channels/backend/communication_channels/channels/page.js +0 -3
- package/dist/modules/communication_channels/backend/communication_channels/channels/page.js.map +2 -2
- package/dist/modules/communication_channels/commands/ingest-inbound-message.js +1 -14
- package/dist/modules/communication_channels/commands/ingest-inbound-message.js.map +2 -2
- package/dist/modules/communication_channels/di.js +1 -7
- package/dist/modules/communication_channels/di.js.map +2 -2
- package/dist/modules/communication_channels/lib/email-capabilities.js +1 -4
- package/dist/modules/communication_channels/lib/email-capabilities.js.map +2 -2
- package/dist/modules/communication_channels/lib/test-seed.js +2 -41
- package/dist/modules/communication_channels/lib/test-seed.js.map +2 -2
- package/dist/modules/configs/lib/system-status.js +0 -9
- package/dist/modules/configs/lib/system-status.js.map +2 -2
- package/dist/modules/currencies/backend/currencies/page.js +1 -3
- package/dist/modules/currencies/backend/currencies/page.js.map +2 -2
- package/dist/modules/currencies/backend/exchange-rates/page.js +1 -3
- package/dist/modules/currencies/backend/exchange-rates/page.js.map +2 -2
- package/dist/modules/customer_accounts/api/admin/domain-mappings.js +0 -9
- package/dist/modules/customer_accounts/api/admin/domain-mappings.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js +1 -3
- package/dist/modules/customer_accounts/backend/customer_accounts/roles/page.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.js +84 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/page.js +7 -81
- package/dist/modules/customer_accounts/backend/customer_accounts/settings/page.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.js +523 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/PortalUserDetailPageClient.js +731 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/PortalUserDetailPageClient.js.map +7 -0
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/page.js +7 -727
- package/dist/modules/customer_accounts/backend/customer_accounts/users/[id]/page.js.map +2 -2
- package/dist/modules/customer_accounts/backend/customer_accounts/users/page.js +7 -521
- package/dist/modules/customer_accounts/backend/customer_accounts/users/page.js.map +2 -2
- package/dist/modules/customer_accounts/extension-points.js +1 -1
- package/dist/modules/customer_accounts/extension-points.js.map +2 -2
- package/dist/modules/customer_accounts/lib/portalUrl.js +69 -0
- package/dist/modules/customer_accounts/lib/portalUrl.js.map +7 -0
- package/dist/modules/customer_accounts/services/domainMappingService.js +0 -10
- package/dist/modules/customer_accounts/services/domainMappingService.js.map +2 -2
- package/dist/modules/customers/ai-tools/companies-pack.js +1 -4
- package/dist/modules/customers/ai-tools/companies-pack.js.map +2 -2
- package/dist/modules/customers/ai-tools/deal-analyzer-pack.js +2 -13
- package/dist/modules/customers/ai-tools/deal-analyzer-pack.js.map +2 -2
- package/dist/modules/customers/ai-tools/deals-pack.js +6 -52
- package/dist/modules/customers/ai-tools/deals-pack.js.map +2 -2
- package/dist/modules/customers/ai-tools/people-pack.js +1 -4
- package/dist/modules/customers/ai-tools/people-pack.js.map +2 -2
- package/dist/modules/customers/api/activities/route.js +6 -48
- package/dist/modules/customers/api/activities/route.js.map +2 -2
- package/dist/modules/customers/api/companies/[id]/people/route.js +64 -20
- package/dist/modules/customers/api/companies/[id]/people/route.js.map +2 -2
- package/dist/modules/customers/api/companies/[id]/route.js +94 -17
- package/dist/modules/customers/api/companies/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/dashboard/widgets/customer-todos/route.js +5 -8
- package/dist/modules/customers/api/dashboard/widgets/customer-todos/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/companies/route.js +1 -1
- package/dist/modules/customers/api/deals/[id]/companies/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/people/route.js +1 -1
- package/dist/modules/customers/api/deals/[id]/people/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/route.js +25 -8
- package/dist/modules/customers/api/deals/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/deals/[id]/stats/route.js +22 -3
- package/dist/modules/customers/api/deals/[id]/stats/route.js.map +2 -2
- package/dist/modules/customers/api/deals/aggregate/route.js +4 -11
- package/dist/modules/customers/api/deals/aggregate/route.js.map +2 -2
- package/dist/modules/customers/api/deals/map/route.js +1 -2
- package/dist/modules/customers/api/deals/map/route.js.map +2 -2
- package/dist/modules/customers/api/deals/route.js +1 -38
- package/dist/modules/customers/api/deals/route.js.map +2 -2
- package/dist/modules/customers/api/entity-roles-factory.js +4 -4
- package/dist/modules/customers/api/entity-roles-factory.js.map +2 -2
- package/dist/modules/customers/api/interactions/route.js +1 -3
- package/dist/modules/customers/api/interactions/route.js.map +2 -2
- package/dist/modules/customers/api/interactions/tasks/route.js +4 -27
- package/dist/modules/customers/api/interactions/tasks/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js +3 -4
- package/dist/modules/customers/api/people/[id]/companies/[linkId]/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/context.js +1 -1
- package/dist/modules/customers/api/people/[id]/companies/context.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/companies/enriched/route.js +1 -1
- package/dist/modules/customers/api/people/[id]/companies/enriched/route.js.map +2 -2
- package/dist/modules/customers/api/people/[id]/route.js +10 -11
- package/dist/modules/customers/api/people/[id]/route.js.map +2 -2
- package/dist/modules/customers/api/people/check-phone/route.js +9 -51
- package/dist/modules/customers/api/people/check-phone/route.js.map +2 -2
- package/dist/modules/customers/api/todos/route.js +5 -30
- package/dist/modules/customers/api/todos/route.js.map +2 -2
- package/dist/modules/customers/backend/customers/companies/page.js +4 -6
- package/dist/modules/customers/backend/customers/companies/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/[id]/page.js +1 -6
- package/dist/modules/customers/backend/customers/deals/[id]/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/page.js +4 -7
- package/dist/modules/customers/backend/customers/deals/page.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/Lane.js +13 -4
- package/dist/modules/customers/backend/customers/deals/pipeline/components/Lane.js.map +2 -2
- package/dist/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.js +14 -85
- package/dist/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.js.map +2 -2
- package/dist/modules/customers/backend/customers/people/page.js +4 -6
- package/dist/modules/customers/backend/customers/people/page.js.map +2 -2
- package/dist/modules/customers/backend/hooks/useEmailDuplicateCheck.js +3 -9
- package/dist/modules/customers/backend/hooks/useEmailDuplicateCheck.js.map +2 -2
- package/dist/modules/customers/commands/deals.js +34 -21
- package/dist/modules/customers/commands/deals.js.map +2 -2
- package/dist/modules/customers/commands/interactions.js.map +1 -1
- package/dist/modules/customers/commands/personCompanyLinks.js +2 -131
- package/dist/modules/customers/commands/personCompanyLinks.js.map +2 -2
- package/dist/modules/customers/components/CustomerTodosTable.js +0 -1
- package/dist/modules/customers/components/CustomerTodosTable.js.map +2 -2
- package/dist/modules/customers/components/DealsKpiStrip.js +6 -7
- package/dist/modules/customers/components/DealsKpiStrip.js.map +2 -2
- package/dist/modules/customers/components/calendar/AgendaList.js +2 -2
- package/dist/modules/customers/components/calendar/AgendaList.js.map +2 -2
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js +1 -1
- package/dist/modules/customers/components/calendar/CalendarEventEditor.js.map +2 -2
- package/dist/modules/customers/components/calendar/CalendarScreen.js +1 -1
- package/dist/modules/customers/components/calendar/CalendarScreen.js.map +2 -2
- package/dist/modules/customers/components/calendar/CalendarSettingsModal.js +1 -1
- package/dist/modules/customers/components/calendar/CalendarSettingsModal.js.map +2 -2
- package/dist/modules/customers/components/calendar/EventBlock.js +1 -1
- package/dist/modules/customers/components/calendar/EventBlock.js.map +2 -2
- package/dist/modules/customers/components/calendar/EventPeekPopover.js +2 -3
- package/dist/modules/customers/components/calendar/EventPeekPopover.js.map +2 -2
- package/dist/modules/customers/components/calendar/editor/PeopleField.js +5 -40
- package/dist/modules/customers/components/calendar/editor/PeopleField.js.map +2 -2
- package/dist/modules/customers/components/calendar/editor/hooks.js +1 -2
- package/dist/modules/customers/components/calendar/editor/hooks.js.map +2 -2
- package/dist/modules/customers/components/calendar/types.js +1 -1
- package/dist/modules/customers/components/calendar/types.js.map +2 -2
- package/dist/modules/customers/components/detail/AssignRoleDialog.js +33 -28
- package/dist/modules/customers/components/detail/AssignRoleDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyKpiBar.js +4 -5
- package/dist/modules/customers/components/detail/CompanyKpiBar.js.map +2 -2
- package/dist/modules/customers/components/detail/CompanyPeopleSection.js +1 -3
- package/dist/modules/customers/components/detail/CompanyPeopleSection.js.map +2 -2
- package/dist/modules/customers/components/detail/DealForm.js +7 -19
- package/dist/modules/customers/components/detail/DealForm.js.map +2 -2
- package/dist/modules/customers/components/detail/DealsSection.js +5 -6
- package/dist/modules/customers/components/detail/DealsSection.js.map +2 -2
- package/dist/modules/customers/components/detail/EntityTagsDialog.js +11 -35
- package/dist/modules/customers/components/detail/EntityTagsDialog.js.map +2 -2
- package/dist/modules/customers/components/detail/PersonCompaniesSection.js +1 -3
- package/dist/modules/customers/components/detail/PersonCompaniesSection.js.map +2 -2
- package/dist/modules/customers/components/detail/hooks/usePersonTasks.js +13 -19
- package/dist/modules/customers/components/detail/hooks/usePersonTasks.js.map +2 -2
- package/dist/modules/customers/components/detail/schedule/ParticipantsField.js +4 -4
- package/dist/modules/customers/components/detail/schedule/ParticipantsField.js.map +2 -2
- package/dist/modules/customers/components/detail/schedule/useScheduleFormState.js +3 -3
- package/dist/modules/customers/components/detail/schedule/useScheduleFormState.js.map +2 -2
- package/dist/modules/customers/components/detail/utils.js +5 -5
- package/dist/modules/customers/components/detail/utils.js.map +2 -2
- package/dist/modules/customers/data/entities.js.map +1 -1
- package/dist/modules/customers/data/validators.js +3 -32
- package/dist/modules/customers/data/validators.js.map +2 -2
- package/dist/modules/customers/events.js +0 -5
- package/dist/modules/customers/events.js.map +2 -2
- package/dist/modules/customers/lib/calendar/conflicts.js +2 -8
- package/dist/modules/customers/lib/calendar/conflicts.js.map +2 -2
- package/dist/modules/customers/lib/calendar/editorPayload.js +2 -3
- package/dist/modules/customers/lib/calendar/editorPayload.js.map +2 -2
- package/dist/modules/customers/lib/calendar/mapItem.js +3 -8
- package/dist/modules/customers/lib/calendar/mapItem.js.map +2 -2
- package/dist/modules/customers/lib/dealStatus.js +0 -30
- package/dist/modules/customers/lib/dealStatus.js.map +2 -2
- package/dist/modules/customers/lib/findPeopleByAddresses.js +0 -1
- package/dist/modules/customers/lib/findPeopleByAddresses.js.map +2 -2
- package/dist/modules/customers/lib/personCompanies.js +2 -100
- package/dist/modules/customers/lib/personCompanies.js.map +2 -2
- package/dist/modules/customers/lib/todoCompatibility.js +0 -12
- package/dist/modules/customers/lib/todoCompatibility.js.map +2 -2
- package/dist/modules/dashboards/lib/widgetScope.js +1 -6
- package/dist/modules/dashboards/lib/widgetScope.js.map +2 -2
- package/dist/modules/data_sync/backend/data-sync/page.js +1 -3
- package/dist/modules/data_sync/backend/data-sync/page.js.map +2 -2
- package/dist/modules/data_sync/lib/sync-engine.js +6 -72
- package/dist/modules/data_sync/lib/sync-engine.js.map +2 -2
- package/dist/modules/data_sync/workers/sync-export.js +1 -5
- package/dist/modules/data_sync/workers/sync-export.js.map +2 -2
- package/dist/modules/data_sync/workers/sync-import.js +1 -5
- package/dist/modules/data_sync/workers/sync-import.js.map +2 -2
- package/dist/modules/devices/api/admin/devices/[id]/route.js +32 -5
- package/dist/modules/devices/api/admin/devices/[id]/route.js.map +2 -2
- package/dist/modules/devices/api/admin/devices/route.js +1 -14
- package/dist/modules/devices/api/admin/devices/route.js.map +2 -2
- package/dist/modules/devices/api/deviceList.js +12 -99
- package/dist/modules/devices/api/deviceList.js.map +2 -2
- package/dist/modules/devices/api/openapi.js +1 -3
- package/dist/modules/devices/api/openapi.js.map +2 -2
- package/dist/modules/devices/api/route.js +1 -9
- package/dist/modules/devices/api/route.js.map +2 -2
- package/dist/modules/devices/backend/devices/[id]/page.js +8 -8
- package/dist/modules/devices/backend/devices/[id]/page.js.map +2 -2
- package/dist/modules/devices/backend/devices/page.js +13 -15
- package/dist/modules/devices/backend/devices/page.js.map +2 -2
- package/dist/modules/directory/backend/directory/organizations/page.js +1 -2
- package/dist/modules/directory/backend/directory/organizations/page.js.map +2 -2
- package/dist/modules/directory/backend/directory/tenants/page.js +1 -2
- package/dist/modules/directory/backend/directory/tenants/page.js.map +2 -2
- package/dist/modules/directory/di.js +0 -9
- package/dist/modules/directory/di.js.map +2 -2
- package/dist/modules/directory/utils/organizationScope.js.map +2 -2
- package/dist/modules/entities/api/records.js +2 -4
- package/dist/modules/entities/api/records.js.map +2 -2
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js +1 -3
- package/dist/modules/entities/backend/entities/user/[entityId]/records/page.js.map +2 -2
- package/dist/modules/eudr/api/plots/route.js +1 -5
- package/dist/modules/eudr/api/plots/route.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/evidence-submissions/[id]/page.meta.js +3 -1
- package/dist/modules/eudr/backend/eudr/evidence-submissions/[id]/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/evidence-submissions/create/page.meta.js +1 -0
- package/dist/modules/eudr/backend/eudr/evidence-submissions/create/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/evidence-submissions/page.js +0 -3
- package/dist/modules/eudr/backend/eudr/evidence-submissions/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/evidence-submissions/page.meta.js +4 -1
- package/dist/modules/eudr/backend/eudr/evidence-submissions/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/page.meta.js +2 -2
- package/dist/modules/eudr/backend/eudr/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/[id]/page.js +8 -2
- package/dist/modules/eudr/backend/eudr/plots/[id]/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/[id]/page.meta.js +3 -1
- package/dist/modules/eudr/backend/eudr/plots/[id]/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/create/page.js +8 -2
- package/dist/modules/eudr/backend/eudr/plots/create/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/create/page.meta.js +1 -0
- package/dist/modules/eudr/backend/eudr/plots/create/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/page.js +0 -3
- package/dist/modules/eudr/backend/eudr/plots/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/plots/page.meta.js +4 -1
- package/dist/modules/eudr/backend/eudr/plots/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/product-mappings/[id]/page.meta.js +3 -1
- package/dist/modules/eudr/backend/eudr/product-mappings/[id]/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/product-mappings/create/page.meta.js +1 -0
- package/dist/modules/eudr/backend/eudr/product-mappings/create/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/product-mappings/page.js +0 -3
- package/dist/modules/eudr/backend/eudr/product-mappings/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/product-mappings/page.meta.js +4 -1
- package/dist/modules/eudr/backend/eudr/product-mappings/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/risk-assessments/[id]/page.meta.js +3 -1
- package/dist/modules/eudr/backend/eudr/risk-assessments/[id]/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/risk-assessments/create/page.meta.js +1 -0
- package/dist/modules/eudr/backend/eudr/risk-assessments/create/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/risk-assessments/page.js +0 -3
- package/dist/modules/eudr/backend/eudr/risk-assessments/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/risk-assessments/page.meta.js +4 -1
- package/dist/modules/eudr/backend/eudr/risk-assessments/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/statements/[id]/page.js +2 -0
- package/dist/modules/eudr/backend/eudr/statements/[id]/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/statements/[id]/page.meta.js +3 -1
- package/dist/modules/eudr/backend/eudr/statements/[id]/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/statements/create/page.meta.js +1 -0
- package/dist/modules/eudr/backend/eudr/statements/create/page.meta.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/statements/page.js +30 -28
- package/dist/modules/eudr/backend/eudr/statements/page.js.map +2 -2
- package/dist/modules/eudr/backend/eudr/statements/page.meta.js +4 -1
- package/dist/modules/eudr/backend/eudr/statements/page.meta.js.map +2 -2
- package/dist/modules/eudr/commands/statements.js +8 -3
- package/dist/modules/eudr/commands/statements.js.map +2 -2
- package/dist/modules/eudr/components/crudErrorI18n.js +21 -1
- package/dist/modules/eudr/components/crudErrorI18n.js.map +2 -2
- package/dist/modules/eudr/components/formConfig.js +6 -2
- package/dist/modules/eudr/components/formConfig.js.map +2 -2
- package/dist/modules/eudr/data/validators.js +1 -4
- package/dist/modules/eudr/data/validators.js.map +2 -2
- package/dist/modules/eudr/lib/statement-lifecycle.js +9 -1
- package/dist/modules/eudr/lib/statement-lifecycle.js.map +2 -2
- package/dist/modules/feature_toggles/components/FeatureTogglesTable.js +0 -1
- package/dist/modules/feature_toggles/components/FeatureTogglesTable.js.map +2 -2
- package/dist/modules/feature_toggles/components/OverridesTable.js +0 -1
- package/dist/modules/feature_toggles/components/OverridesTable.js.map +2 -2
- package/dist/modules/feature_toggles/defaults.json +8 -0
- package/dist/modules/inbox_ops/backend/inbox-ops/log/page.js +0 -3
- package/dist/modules/inbox_ops/backend/inbox-ops/log/page.js.map +2 -2
- package/dist/modules/inbox_ops/backend/inbox-ops/page.js +0 -3
- package/dist/modules/inbox_ops/backend/inbox-ops/page.js.map +2 -2
- package/dist/modules/inbox_ops/lib/htmlToPlainText.js +12 -1
- package/dist/modules/inbox_ops/lib/htmlToPlainText.js.map +2 -2
- package/dist/modules/integrations/api/[id]/credentials/route.js +1 -6
- package/dist/modules/integrations/api/[id]/credentials/route.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/[id]/page.js +29 -38
- package/dist/modules/integrations/backend/integrations/[id]/page.js.map +2 -2
- package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js +9 -36
- package/dist/modules/integrations/backend/integrations/bundle/[id]/page.js.map +2 -2
- package/dist/modules/integrations/data/validators.js +3 -11
- package/dist/modules/integrations/data/validators.js.map +2 -2
- package/dist/modules/integrations/lib/credentials-masking.js +2 -6
- package/dist/modules/integrations/lib/credentials-masking.js.map +2 -2
- package/dist/modules/messages/api/[id]/route.js +1 -29
- package/dist/modules/messages/api/[id]/route.js.map +2 -2
- package/dist/modules/messages/api/openapi.js +2 -17
- package/dist/modules/messages/api/openapi.js.map +2 -2
- package/dist/modules/messages/api/route.js +2 -17
- package/dist/modules/messages/api/route.js.map +2 -2
- package/dist/modules/messages/components/MessagesInboxPageClient.js +14 -7
- package/dist/modules/messages/components/MessagesInboxPageClient.js.map +2 -2
- package/dist/modules/messages/components/inboxFilters.js +0 -15
- package/dist/modules/messages/components/inboxFilters.js.map +2 -2
- package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsConversation.js +1 -11
- package/dist/modules/messages/components/message-detail/hooks/useMessageDetailsConversation.js.map +2 -2
- package/dist/modules/messages/components/message-detail/panels/MessageHeader.js +1 -3
- package/dist/modules/messages/components/message-detail/panels/MessageHeader.js.map +2 -2
- package/dist/modules/messages/components/message-detail/panels/thread-panel.js +1 -2
- package/dist/modules/messages/components/message-detail/panels/thread-panel.js.map +2 -2
- package/dist/modules/messages/components/messageListLabels.js +2 -14
- package/dist/modules/messages/components/messageListLabels.js.map +2 -2
- package/dist/modules/messages/data/validators.js +4 -18
- package/dist/modules/messages/data/validators.js.map +2 -2
- package/dist/modules/payment_gateways/api/webhook/[provider]/route.js +6 -4
- package/dist/modules/payment_gateways/api/webhook/[provider]/route.js.map +2 -2
- package/dist/modules/payment_gateways/backend/payment-gateways/page.js +1 -3
- package/dist/modules/payment_gateways/backend/payment-gateways/page.js.map +2 -2
- package/dist/modules/payment_gateways/lib/webhook-processor.js +0 -7
- package/dist/modules/payment_gateways/lib/webhook-processor.js.map +2 -2
- package/dist/modules/planner/backend/planner/availability-rulesets/page.js +0 -3
- package/dist/modules/planner/backend/planner/availability-rulesets/page.js.map +2 -2
- package/dist/modules/push_notifications/backend/push_notifications/page.js +1 -3
- package/dist/modules/push_notifications/backend/push_notifications/page.js.map +2 -2
- package/dist/modules/push_notifications/backend/push_notifications/send/page.js +1 -1
- package/dist/modules/push_notifications/backend/push_notifications/send/page.js.map +2 -2
- package/dist/modules/query_index/lib/engine.js +51 -150
- package/dist/modules/query_index/lib/engine.js.map +2 -2
- package/dist/modules/query_index/lib/search-tokens.js +3 -79
- package/dist/modules/query_index/lib/search-tokens.js.map +2 -2
- package/dist/modules/resources/backend/resources/resource-types/page.js +1 -3
- package/dist/modules/resources/backend/resources/resource-types/page.js.map +2 -2
- package/dist/modules/resources/backend/resources/resources/page.js +1 -3
- package/dist/modules/resources/backend/resources/resources/page.js.map +2 -2
- package/dist/modules/sales/backend/sales/channels/offers/page.js +0 -3
- package/dist/modules/sales/backend/sales/channels/offers/page.js.map +2 -2
- package/dist/modules/sales/backend/sales/channels/page.js +0 -3
- package/dist/modules/sales/backend/sales/channels/page.js.map +2 -2
- package/dist/modules/sales/backend/sales/documents/[id]/page.js +8 -10
- package/dist/modules/sales/backend/sales/documents/[id]/page.js.map +2 -2
- package/dist/modules/sales/commands/documents.js +1 -79
- package/dist/modules/sales/commands/documents.js.map +2 -2
- package/dist/modules/sales/components/PriceWithCurrency.js +5 -7
- package/dist/modules/sales/components/PriceWithCurrency.js.map +2 -2
- package/dist/modules/sales/components/channels/SalesChannelOffersPanel.js +0 -3
- package/dist/modules/sales/components/channels/SalesChannelOffersPanel.js.map +2 -2
- package/dist/modules/sales/components/documents/AdjustmentsSection.js +6 -8
- package/dist/modules/sales/components/documents/AdjustmentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/ItemsSection.js +22 -51
- package/dist/modules/sales/components/documents/ItemsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/LineItemDialog.js +19 -84
- package/dist/modules/sales/components/documents/LineItemDialog.js.map +2 -2
- package/dist/modules/sales/components/documents/PaymentsSection.js +9 -23
- package/dist/modules/sales/components/documents/PaymentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/ReturnsSection.js +6 -8
- package/dist/modules/sales/components/documents/ReturnsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js +14 -68
- package/dist/modules/sales/components/documents/SalesDocumentsTable.js.map +2 -2
- package/dist/modules/sales/components/documents/SalesOrderDraftLines.js +5 -6
- package/dist/modules/sales/components/documents/SalesOrderDraftLines.js.map +2 -2
- package/dist/modules/sales/components/documents/ShipmentDialog.js +4 -5
- package/dist/modules/sales/components/documents/ShipmentDialog.js.map +2 -2
- package/dist/modules/sales/components/documents/ShipmentsSection.js +6 -8
- package/dist/modules/sales/components/documents/ShipmentsSection.js.map +2 -2
- package/dist/modules/sales/components/documents/lineItemUtils.js +2 -2
- package/dist/modules/sales/components/documents/lineItemUtils.js.map +2 -2
- package/dist/modules/sales/data/entities.js +2 -8
- package/dist/modules/sales/data/entities.js.map +2 -2
- package/dist/modules/sales/extension-points.js +0 -1
- package/dist/modules/sales/extension-points.js.map +2 -2
- package/dist/modules/sales/setup.js +0 -2
- package/dist/modules/sales/setup.js.map +2 -2
- package/dist/modules/sales/widgets/injection/document-history/widget.client.js +44 -2
- package/dist/modules/sales/widgets/injection/document-history/widget.client.js.map +2 -2
- package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js +2 -10
- package/dist/modules/sales/widgets/injection/payment-gateway-status-column/widget.js.map +2 -2
- package/dist/modules/sales/widgets/injection-table.js +7 -4
- package/dist/modules/sales/widgets/injection-table.js.map +2 -2
- package/dist/modules/staff/backend/staff/leave-requests/page.js +0 -3
- package/dist/modules/staff/backend/staff/leave-requests/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/my-leave-requests/page.js +0 -3
- package/dist/modules/staff/backend/staff/my-leave-requests/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/team-members/page.js +0 -3
- package/dist/modules/staff/backend/staff/team-members/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/team-roles/page.js +0 -3
- package/dist/modules/staff/backend/staff/team-roles/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js +0 -3
- package/dist/modules/staff/backend/staff/teams/[id]/edit/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/teams/page.js +0 -3
- package/dist/modules/staff/backend/staff/teams/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/timesheets/page.js +18 -29
- package/dist/modules/staff/backend/staff/timesheets/page.js.map +2 -2
- package/dist/modules/staff/backend/staff/timesheets/projects/page.js +0 -3
- package/dist/modules/staff/backend/staff/timesheets/projects/page.js.map +2 -2
- package/dist/modules/sync_excel/lib/adapters/customers.js +0 -1
- package/dist/modules/sync_excel/lib/adapters/customers.js.map +2 -2
- package/dist/modules/warranty_claims/api/assignees/route.js +3 -3
- package/dist/modules/warranty_claims/api/assignees/route.js.map +2 -2
- package/dist/modules/warranty_claims/api/portal/attachments/route.js +2 -2
- package/dist/modules/warranty_claims/api/portal/attachments/route.js.map +2 -2
- package/dist/modules/warranty_claims/api/portal/claims/route.js +9 -12
- package/dist/modules/warranty_claims/api/portal/claims/route.js.map +2 -2
- package/dist/modules/warranty_claims/backend/page.js +0 -3
- package/dist/modules/warranty_claims/backend/page.js.map +2 -2
- package/dist/modules/warranty_claims/backend/warranty_claims/registrations/page.js +0 -3
- package/dist/modules/warranty_claims/backend/warranty_claims/registrations/page.js.map +2 -2
- package/dist/modules/warranty_claims/backend/warranty_claims/troubleshooting-guides/page.js +0 -3
- package/dist/modules/warranty_claims/backend/warranty_claims/troubleshooting-guides/page.js.map +2 -2
- package/dist/modules/warranty_claims/backend/warranty_claims/vendor-policies/page.js +0 -3
- package/dist/modules/warranty_claims/backend/warranty_claims/vendor-policies/page.js.map +2 -2
- package/dist/modules/warranty_claims/frontend/[orgSlug]/portal/claims/page.js +0 -3
- package/dist/modules/warranty_claims/frontend/[orgSlug]/portal/claims/page.js.map +2 -2
- package/dist/modules/wms/api/warehouses/route.js +9 -13
- package/dist/modules/wms/api/warehouses/route.js.map +2 -2
- package/dist/modules/wms/api/zones/route.js +2 -15
- package/dist/modules/wms/api/zones/route.js.map +2 -2
- package/dist/modules/wms/commands/configuration.js +9 -121
- package/dist/modules/wms/commands/configuration.js.map +2 -2
- package/dist/modules/wms/commands/inventory-actions.js +0 -3
- package/dist/modules/wms/commands/inventory-actions.js.map +2 -2
- package/dist/modules/wms/commands/shared.js +1 -9
- package/dist/modules/wms/commands/shared.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsConfigurationPage.js +111 -76
- package/dist/modules/wms/components/backend/WmsConfigurationPage.js.map +3 -3
- package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js +0 -1
- package/dist/modules/wms/components/backend/WmsInventoryConsolePage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js +20 -16
- package/dist/modules/wms/components/backend/WmsLocationDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js +10 -6
- package/dist/modules/wms/components/backend/WmsLotDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsLotsListPage.js +0 -1
- package/dist/modules/wms/components/backend/WmsLotsListPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js +11 -7
- package/dist/modules/wms/components/backend/WmsOperationalDashboardPage.js.map +2 -2
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js +10 -6
- package/dist/modules/wms/components/backend/WmsSkuDetailPage.js.map +2 -2
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js +20 -27
- package/dist/modules/wms/components/backend/inventoryMutationLoaders.js.map +2 -2
- package/dist/modules/workflows/backend/definitions/page.js +1 -3
- package/dist/modules/workflows/backend/definitions/page.js.map +2 -2
- package/dist/modules/workflows/backend/events/page.js +1 -3
- package/dist/modules/workflows/backend/events/page.js.map +2 -2
- package/dist/modules/workflows/backend/instances/page.js +1 -3
- package/dist/modules/workflows/backend/instances/page.js.map +2 -2
- package/dist/modules/workflows/backend/tasks/page.js +1 -3
- package/dist/modules/workflows/backend/tasks/page.js.map +2 -2
- package/dist/modules/workflows/lib/activity-executor.js +0 -4
- package/dist/modules/workflows/lib/activity-executor.js.map +2 -2
- package/package.json +10 -9
- package/src/helpers/integration/api.ts +1 -33
- package/src/helpers/integration/communicationChannelsFixtures.ts +1 -69
- package/src/modules/api_keys/api/keys/route.ts +1 -3
- package/src/modules/api_keys/backend/api-keys/page.tsx +1 -4
- package/src/modules/attachments/AGENTS.md +0 -15
- package/src/modules/attachments/api/route.ts +2 -2
- package/src/modules/attachments/components/AttachmentLibrary.tsx +0 -3
- package/src/modules/attachments/di.ts +0 -16
- package/src/modules/attachments/i18n/de.json +0 -5
- package/src/modules/attachments/i18n/en.json +0 -5
- package/src/modules/attachments/i18n/es.json +0 -5
- package/src/modules/attachments/i18n/ko.json +0 -5
- package/src/modules/attachments/i18n/pl.json +0 -5
- package/src/modules/attachments/index.ts +0 -10
- package/src/modules/attachments/lib/scoped-upload-service.ts +0 -46
- package/src/modules/attachments/lib/upload-limits.ts +2 -6
- package/src/modules/audit_logs/backend/audit-logs/page.tsx +0 -8
- package/src/modules/audit_logs/lib/display-helpers.tsx +32 -42
- package/src/modules/audit_logs/services/actionLogService.ts +11 -74
- package/src/modules/auth/acl.ts +6 -30
- package/src/modules/auth/api/feature-check.ts +3 -10
- package/src/modules/auth/api/login.ts +24 -9
- package/src/modules/auth/api/roles/acl/route.ts +39 -42
- package/src/modules/auth/api/routeError.ts +30 -0
- package/src/modules/auth/api/session/refresh.ts +1 -32
- package/src/modules/auth/api/users/acl/route.ts +101 -185
- package/src/modules/auth/backend/roles/[id]/edit/page.meta.ts +2 -5
- package/src/modules/auth/backend/roles/page.tsx +2 -4
- package/src/modules/auth/backend/users/[id]/edit/page.meta.ts +2 -5
- package/src/modules/auth/backend/users/page.tsx +2 -3
- package/src/modules/auth/components/AclEditor.tsx +33 -63
- package/src/modules/auth/data/entities.ts +1 -4
- package/src/modules/auth/data/validators.ts +0 -5
- package/src/modules/auth/di.ts +16 -46
- package/src/modules/auth/frontend/reset/[token]/page.tsx +0 -74
- package/src/modules/auth/i18n/de.json +0 -389
- package/src/modules/auth/i18n/en.json +0 -389
- package/src/modules/auth/i18n/es.json +0 -389
- package/src/modules/auth/i18n/ko.json +0 -389
- package/src/modules/auth/i18n/pl.json +2 -391
- package/src/modules/auth/lib/grantChecks.ts +0 -6
- package/src/modules/auth/services/authService.ts +2 -18
- package/src/modules/auth/services/rbacService.ts +24 -110
- package/src/modules/business_rules/backend/logs/page.tsx +1 -4
- package/src/modules/business_rules/backend/rules/[id]/page.meta.ts +5 -0
- package/src/modules/business_rules/backend/rules/create/page.meta.ts +5 -1
- package/src/modules/business_rules/backend/rules/page.tsx +1 -4
- package/src/modules/business_rules/backend/sets/[id]/page.meta.ts +5 -0
- package/src/modules/business_rules/backend/sets/create/page.meta.ts +5 -1
- package/src/modules/business_rules/backend/sets/page.tsx +1 -4
- package/src/modules/business_rules/lib/expression-evaluator.ts +9 -9
- package/src/modules/business_rules/lib/rule-evaluator.ts +9 -10
- package/src/modules/catalog/ai-agents.ts +1 -1
- package/src/modules/catalog/ai-tools/merchandising-pack.ts +2 -2
- package/src/modules/catalog/backend/catalog/products/MerchandisingAssistantSheet.tsx +5 -12
- package/src/modules/catalog/components/categories/CategoriesDataTable.tsx +0 -3
- package/src/modules/catalog/components/products/ProductsDataTable.tsx +0 -7
- package/src/modules/catalog/i18n/de.json +0 -1
- package/src/modules/catalog/i18n/en.json +0 -1
- package/src/modules/catalog/i18n/es.json +0 -1
- package/src/modules/catalog/i18n/ko.json +0 -1
- package/src/modules/catalog/i18n/pl.json +0 -1
- package/src/modules/catalog/widgets/injection/merchandising-assistant-trigger/widget.client.tsx +0 -4
- package/src/modules/communication_channels/api/post/channels/[id]/test-send/route.ts +1 -17
- package/src/modules/communication_channels/api/post/test-seed/route.ts +16 -155
- package/src/modules/communication_channels/backend/communication_channels/channels/page.tsx +0 -4
- package/src/modules/communication_channels/commands/ingest-inbound-message.ts +1 -38
- package/src/modules/communication_channels/di.ts +0 -7
- package/src/modules/communication_channels/lib/adapter.ts +0 -14
- package/src/modules/communication_channels/lib/email-capabilities.ts +0 -4
- package/src/modules/communication_channels/lib/test-seed.ts +4 -64
- package/src/modules/configs/i18n/de.json +0 -2
- package/src/modules/configs/i18n/en.json +0 -2
- package/src/modules/configs/i18n/es.json +0 -2
- package/src/modules/configs/i18n/ko.json +0 -2
- package/src/modules/configs/i18n/pl.json +0 -2
- package/src/modules/configs/lib/system-status.ts +0 -9
- package/src/modules/currencies/backend/currencies/page.tsx +1 -4
- package/src/modules/currencies/backend/exchange-rates/page.tsx +1 -4
- package/src/modules/customer_accounts/api/admin/domain-mappings.ts +0 -7
- package/src/modules/customer_accounts/backend/customer_accounts/roles/page.tsx +1 -4
- package/src/modules/customer_accounts/backend/customer_accounts/settings/CustomerAccountsSettingsPageClient.tsx +138 -0
- package/src/modules/customer_accounts/backend/customer_accounts/settings/page.tsx +8 -132
- package/src/modules/customer_accounts/backend/customer_accounts/users/PortalUsersPageClient.tsx +598 -0
- package/src/modules/customer_accounts/backend/customer_accounts/users/[id]/PortalUserDetailPageClient.tsx +838 -0
- package/src/modules/customer_accounts/backend/customer_accounts/users/[id]/page.tsx +6 -838
- package/src/modules/customer_accounts/backend/customer_accounts/users/page.tsx +6 -590
- package/src/modules/customer_accounts/extension-points.ts +1 -1
- package/src/modules/customer_accounts/lib/portalUrl.ts +112 -0
- package/src/modules/customer_accounts/services/domainMappingService.ts +0 -10
- package/src/modules/customers/ai-tools/companies-pack.ts +1 -4
- package/src/modules/customers/ai-tools/deal-analyzer-pack.ts +2 -17
- package/src/modules/customers/ai-tools/deals-pack.ts +1 -66
- package/src/modules/customers/ai-tools/people-pack.ts +1 -4
- package/src/modules/customers/api/activities/route.ts +0 -45
- package/src/modules/customers/api/companies/[id]/people/route.ts +73 -24
- package/src/modules/customers/api/companies/[id]/route.ts +107 -24
- package/src/modules/customers/api/dashboard/widgets/customer-todos/route.ts +8 -16
- package/src/modules/customers/api/deals/[id]/companies/route.ts +1 -4
- package/src/modules/customers/api/deals/[id]/people/route.ts +1 -4
- package/src/modules/customers/api/deals/[id]/route.ts +28 -17
- package/src/modules/customers/api/deals/[id]/stats/route.ts +25 -10
- package/src/modules/customers/api/deals/aggregate/route.ts +4 -14
- package/src/modules/customers/api/deals/map/route.ts +0 -1
- package/src/modules/customers/api/deals/route.ts +1 -50
- package/src/modules/customers/api/entity-roles-factory.ts +4 -8
- package/src/modules/customers/api/interactions/route.ts +2 -8
- package/src/modules/customers/api/interactions/tasks/route.ts +1 -24
- package/src/modules/customers/api/people/[id]/companies/[linkId]/route.ts +4 -12
- package/src/modules/customers/api/people/[id]/companies/context.ts +1 -4
- package/src/modules/customers/api/people/[id]/companies/enriched/route.ts +1 -4
- package/src/modules/customers/api/people/[id]/route.ts +11 -16
- package/src/modules/customers/api/people/check-phone/route.ts +10 -75
- package/src/modules/customers/api/todos/route.ts +2 -27
- package/src/modules/customers/backend/customers/companies/page.tsx +4 -7
- package/src/modules/customers/backend/customers/deals/[id]/page.tsx +2 -7
- package/src/modules/customers/backend/customers/deals/page.tsx +4 -10
- package/src/modules/customers/backend/customers/deals/pipeline/components/Lane.tsx +14 -5
- package/src/modules/customers/backend/customers/deals/pipeline/components/StatusFilterPopover.tsx +27 -109
- package/src/modules/customers/backend/customers/people/page.tsx +4 -7
- package/src/modules/customers/backend/hooks/useEmailDuplicateCheck.ts +4 -12
- package/src/modules/customers/commands/deals.ts +59 -34
- package/src/modules/customers/commands/interactions.ts +1 -1
- package/src/modules/customers/commands/personCompanyLinks.ts +8 -224
- package/src/modules/customers/components/CustomerTodosTable.tsx +0 -2
- package/src/modules/customers/components/DealsKpiStrip.tsx +7 -7
- package/src/modules/customers/components/calendar/AgendaList.tsx +3 -3
- package/src/modules/customers/components/calendar/CalendarEventEditor.tsx +1 -1
- package/src/modules/customers/components/calendar/CalendarScreen.tsx +1 -1
- package/src/modules/customers/components/calendar/CalendarSettingsModal.tsx +1 -1
- package/src/modules/customers/components/calendar/EventBlock.tsx +2 -2
- package/src/modules/customers/components/calendar/EventPeekPopover.tsx +2 -4
- package/src/modules/customers/components/calendar/editor/PeopleField.tsx +5 -61
- package/src/modules/customers/components/calendar/editor/hooks.ts +1 -7
- package/src/modules/customers/components/calendar/types.ts +2 -2
- package/src/modules/customers/components/detail/AssignRoleDialog.tsx +12 -7
- package/src/modules/customers/components/detail/CompanyKpiBar.tsx +4 -5
- package/src/modules/customers/components/detail/CompanyPeopleSection.tsx +1 -8
- package/src/modules/customers/components/detail/DealForm.tsx +2 -22
- package/src/modules/customers/components/detail/DealsSection.tsx +5 -11
- package/src/modules/customers/components/detail/EntityTagsDialog.tsx +12 -58
- package/src/modules/customers/components/detail/PersonCompaniesSection.tsx +1 -8
- package/src/modules/customers/components/detail/hooks/usePersonTasks.ts +14 -23
- package/src/modules/customers/components/detail/schedule/ParticipantsField.tsx +5 -5
- package/src/modules/customers/components/detail/schedule/useScheduleFormState.ts +5 -5
- package/src/modules/customers/components/detail/types.ts +1 -1
- package/src/modules/customers/components/detail/utils.ts +5 -15
- package/src/modules/customers/data/entities.ts +1 -1
- package/src/modules/customers/data/validators.ts +9 -50
- package/src/modules/customers/events.ts +0 -5
- package/src/modules/customers/i18n/de.json +1 -9
- package/src/modules/customers/i18n/en.json +1 -9
- package/src/modules/customers/i18n/es.json +1 -9
- package/src/modules/customers/i18n/ko.json +1 -9
- package/src/modules/customers/i18n/pl.json +1 -9
- package/src/modules/customers/lib/calendar/conflicts.ts +2 -10
- package/src/modules/customers/lib/calendar/editorPayload.ts +3 -4
- package/src/modules/customers/lib/calendar/mapItem.ts +3 -8
- package/src/modules/customers/lib/dealStatus.ts +0 -42
- package/src/modules/customers/lib/findPeopleByAddresses.ts +6 -8
- package/src/modules/customers/lib/personCompanies.ts +1 -136
- package/src/modules/customers/lib/todoCompatibility.ts +1 -19
- package/src/modules/dashboards/i18n/es.json +4 -4
- package/src/modules/dashboards/i18n/pl.json +7 -7
- package/src/modules/dashboards/lib/widgetScope.ts +0 -6
- package/src/modules/data_sync/AGENTS.md +1 -1
- package/src/modules/data_sync/backend/data-sync/page.tsx +1 -4
- package/src/modules/data_sync/lib/adapter.ts +0 -36
- package/src/modules/data_sync/lib/sync-engine.ts +5 -113
- package/src/modules/data_sync/workers/sync-export.ts +0 -4
- package/src/modules/data_sync/workers/sync-import.ts +0 -4
- package/src/modules/devices/AGENTS.md +0 -8
- package/src/modules/devices/api/admin/devices/[id]/route.ts +34 -5
- package/src/modules/devices/api/admin/devices/route.ts +1 -14
- package/src/modules/devices/api/deviceList.ts +11 -135
- package/src/modules/devices/api/openapi.ts +1 -9
- package/src/modules/devices/api/route.ts +1 -9
- package/src/modules/devices/backend/devices/[id]/page.tsx +15 -15
- package/src/modules/devices/backend/devices/page.tsx +21 -24
- package/src/modules/directory/backend/directory/organizations/page.tsx +1 -3
- package/src/modules/directory/backend/directory/tenants/page.tsx +1 -3
- package/src/modules/directory/di.ts +2 -14
- package/src/modules/directory/utils/organizationScope.ts +15 -4
- package/src/modules/entities/api/records.ts +0 -2
- package/src/modules/entities/backend/entities/user/[entityId]/records/page.tsx +1 -4
- package/src/modules/eudr/api/plots/route.ts +0 -4
- package/src/modules/eudr/backend/eudr/evidence-submissions/[id]/page.meta.ts +2 -0
- package/src/modules/eudr/backend/eudr/evidence-submissions/create/page.meta.ts +1 -0
- package/src/modules/eudr/backend/eudr/evidence-submissions/page.meta.ts +4 -1
- package/src/modules/eudr/backend/eudr/evidence-submissions/page.tsx +0 -4
- package/src/modules/eudr/backend/eudr/page.meta.ts +2 -2
- package/src/modules/eudr/backend/eudr/plots/[id]/page.meta.ts +2 -0
- package/src/modules/eudr/backend/eudr/plots/[id]/page.tsx +8 -2
- package/src/modules/eudr/backend/eudr/plots/create/page.meta.ts +1 -0
- package/src/modules/eudr/backend/eudr/plots/create/page.tsx +8 -2
- package/src/modules/eudr/backend/eudr/plots/page.meta.ts +4 -1
- package/src/modules/eudr/backend/eudr/plots/page.tsx +0 -4
- package/src/modules/eudr/backend/eudr/product-mappings/[id]/page.meta.ts +2 -0
- package/src/modules/eudr/backend/eudr/product-mappings/create/page.meta.ts +1 -0
- package/src/modules/eudr/backend/eudr/product-mappings/page.meta.ts +4 -1
- package/src/modules/eudr/backend/eudr/product-mappings/page.tsx +0 -4
- package/src/modules/eudr/backend/eudr/risk-assessments/[id]/page.meta.ts +2 -0
- package/src/modules/eudr/backend/eudr/risk-assessments/create/page.meta.ts +1 -0
- package/src/modules/eudr/backend/eudr/risk-assessments/page.meta.ts +4 -1
- package/src/modules/eudr/backend/eudr/risk-assessments/page.tsx +0 -4
- package/src/modules/eudr/backend/eudr/statements/[id]/page.meta.ts +2 -0
- package/src/modules/eudr/backend/eudr/statements/[id]/page.tsx +2 -0
- package/src/modules/eudr/backend/eudr/statements/create/page.meta.ts +1 -0
- package/src/modules/eudr/backend/eudr/statements/page.meta.ts +4 -1
- package/src/modules/eudr/backend/eudr/statements/page.tsx +32 -30
- package/src/modules/eudr/commands/statements.ts +7 -2
- package/src/modules/eudr/components/crudErrorI18n.ts +31 -0
- package/src/modules/eudr/components/formConfig.tsx +9 -1
- package/src/modules/eudr/data/validators.ts +1 -16
- package/src/modules/eudr/i18n/de.json +3 -2
- package/src/modules/eudr/i18n/en.json +3 -2
- package/src/modules/eudr/i18n/es.json +3 -2
- package/src/modules/eudr/i18n/ko.json +3 -2
- package/src/modules/eudr/i18n/pl.json +3 -2
- package/src/modules/eudr/lib/statement-lifecycle.ts +8 -0
- package/src/modules/feature_toggles/components/FeatureTogglesTable.tsx +1 -2
- package/src/modules/feature_toggles/components/OverridesTable.tsx +1 -2
- package/src/modules/feature_toggles/defaults.json +8 -0
- package/src/modules/inbox_ops/backend/inbox-ops/log/page.tsx +0 -4
- package/src/modules/inbox_ops/backend/inbox-ops/page.tsx +0 -4
- package/src/modules/inbox_ops/lib/htmlToPlainText.ts +17 -1
- package/src/modules/integrations/api/[id]/credentials/route.ts +4 -6
- package/src/modules/integrations/backend/integrations/[id]/page.tsx +31 -61
- package/src/modules/integrations/backend/integrations/bundle/[id]/page.tsx +9 -44
- package/src/modules/integrations/data/validators.ts +2 -12
- package/src/modules/integrations/i18n/de.json +0 -1
- package/src/modules/integrations/i18n/en.json +0 -1
- package/src/modules/integrations/i18n/es.json +0 -1
- package/src/modules/integrations/i18n/ko.json +0 -1
- package/src/modules/integrations/i18n/pl.json +0 -1
- package/src/modules/integrations/lib/credentials-masking.ts +6 -10
- package/src/modules/messages/api/[id]/route.ts +1 -55
- package/src/modules/messages/api/openapi.ts +0 -20
- package/src/modules/messages/api/route.ts +2 -31
- package/src/modules/messages/components/MessagesInboxPageClient.tsx +16 -9
- package/src/modules/messages/components/inboxFilters.ts +0 -36
- package/src/modules/messages/components/message-detail/hooks/useMessageDetailsConversation.ts +1 -14
- package/src/modules/messages/components/message-detail/panels/MessageHeader.tsx +1 -3
- package/src/modules/messages/components/message-detail/panels/thread-panel.tsx +1 -2
- package/src/modules/messages/components/message-detail/types.ts +0 -3
- package/src/modules/messages/components/messageListLabels.ts +3 -52
- package/src/modules/messages/data/validators.ts +4 -43
- package/src/modules/payment_gateways/api/webhook/[provider]/route.ts +6 -4
- package/src/modules/payment_gateways/backend/payment-gateways/page.tsx +1 -4
- package/src/modules/payment_gateways/lib/webhook-processor.ts +0 -11
- package/src/modules/planner/backend/planner/availability-rulesets/page.tsx +0 -4
- package/src/modules/push_notifications/backend/push_notifications/page.tsx +1 -4
- package/src/modules/push_notifications/backend/push_notifications/send/page.tsx +4 -4
- package/src/modules/query_index/lib/engine.ts +61 -249
- package/src/modules/query_index/lib/search-tokens.ts +3 -135
- package/src/modules/resources/backend/resources/resource-types/page.tsx +1 -4
- package/src/modules/resources/backend/resources/resources/page.tsx +1 -4
- package/src/modules/sales/backend/sales/channels/offers/page.tsx +0 -4
- package/src/modules/sales/backend/sales/channels/page.tsx +0 -4
- package/src/modules/sales/backend/sales/documents/[id]/page.tsx +8 -14
- package/src/modules/sales/commands/documents.ts +0 -93
- package/src/modules/sales/components/PriceWithCurrency.tsx +5 -17
- package/src/modules/sales/components/channels/SalesChannelOffersPanel.tsx +0 -4
- package/src/modules/sales/components/documents/AdjustmentsSection.tsx +5 -6
- package/src/modules/sales/components/documents/ItemsSection.tsx +18 -56
- package/src/modules/sales/components/documents/LineItemDialog.tsx +21 -138
- package/src/modules/sales/components/documents/PaymentsSection.tsx +9 -20
- package/src/modules/sales/components/documents/ReturnsSection.tsx +5 -6
- package/src/modules/sales/components/documents/SalesDocumentsTable.tsx +14 -106
- package/src/modules/sales/components/documents/SalesOrderDraftLines.tsx +5 -6
- package/src/modules/sales/components/documents/ShipmentDialog.tsx +4 -5
- package/src/modules/sales/components/documents/ShipmentsSection.tsx +5 -6
- package/src/modules/sales/components/documents/lineItemUtils.ts +2 -7
- package/src/modules/sales/data/entities.ts +0 -6
- package/src/modules/sales/extension-points.ts +0 -1
- package/src/modules/sales/i18n/de.json +37 -8
- package/src/modules/sales/i18n/en.json +37 -8
- package/src/modules/sales/i18n/es.json +37 -8
- package/src/modules/sales/i18n/ko.json +37 -8
- package/src/modules/sales/i18n/pl.json +37 -8
- package/src/modules/sales/migrations/.snapshot-open-mercato.json +0 -60
- package/src/modules/sales/setup.ts +0 -2
- package/src/modules/sales/widgets/injection/document-history/widget.client.tsx +42 -2
- package/src/modules/sales/widgets/injection/payment-gateway-status-column/widget.ts +1 -9
- package/src/modules/sales/widgets/injection-table.ts +7 -4
- package/src/modules/staff/backend/staff/leave-requests/page.tsx +0 -4
- package/src/modules/staff/backend/staff/my-leave-requests/page.tsx +0 -4
- package/src/modules/staff/backend/staff/team-members/page.tsx +0 -6
- package/src/modules/staff/backend/staff/team-roles/page.tsx +0 -4
- package/src/modules/staff/backend/staff/teams/[id]/edit/page.tsx +0 -4
- package/src/modules/staff/backend/staff/teams/page.tsx +0 -4
- package/src/modules/staff/backend/staff/timesheets/page.tsx +1 -12
- package/src/modules/staff/backend/staff/timesheets/projects/page.tsx +0 -4
- package/src/modules/sync_excel/lib/adapters/customers.ts +0 -5
- package/src/modules/warranty_claims/api/assignees/route.ts +3 -3
- package/src/modules/warranty_claims/api/portal/attachments/route.ts +2 -2
- package/src/modules/warranty_claims/api/portal/claims/route.ts +9 -12
- package/src/modules/warranty_claims/backend/page.tsx +0 -4
- package/src/modules/warranty_claims/backend/warranty_claims/registrations/page.tsx +0 -4
- package/src/modules/warranty_claims/backend/warranty_claims/troubleshooting-guides/page.tsx +0 -4
- package/src/modules/warranty_claims/backend/warranty_claims/vendor-policies/page.tsx +0 -4
- package/src/modules/warranty_claims/frontend/[orgSlug]/portal/claims/page.tsx +0 -4
- package/src/modules/wms/api/warehouses/route.ts +9 -13
- package/src/modules/wms/api/zones/route.ts +0 -16
- package/src/modules/wms/commands/configuration.ts +10 -159
- package/src/modules/wms/commands/inventory-actions.ts +0 -3
- package/src/modules/wms/commands/shared.ts +0 -17
- package/src/modules/wms/components/backend/WmsConfigurationPage.tsx +141 -95
- package/src/modules/wms/components/backend/WmsInventoryConsolePage.tsx +0 -2
- package/src/modules/wms/components/backend/WmsLocationDetailPage.tsx +30 -26
- package/src/modules/wms/components/backend/WmsLotDetailPage.tsx +21 -17
- package/src/modules/wms/components/backend/WmsLotsListPage.tsx +0 -2
- package/src/modules/wms/components/backend/WmsOperationalDashboardPage.tsx +17 -13
- package/src/modules/wms/components/backend/WmsSkuDetailPage.tsx +16 -12
- package/src/modules/wms/components/backend/inventoryMutationLoaders.ts +20 -36
- package/src/modules/wms/i18n/de.json +0 -2
- package/src/modules/wms/i18n/en.json +0 -2
- package/src/modules/wms/i18n/es.json +0 -2
- package/src/modules/wms/i18n/ko.json +0 -2
- package/src/modules/wms/i18n/pl.json +0 -2
- package/src/modules/workflows/backend/definitions/page.tsx +1 -4
- package/src/modules/workflows/backend/events/page.tsx +1 -4
- package/src/modules/workflows/backend/instances/page.tsx +1 -4
- package/src/modules/workflows/backend/tasks/page.tsx +1 -4
- package/src/modules/workflows/lib/activity-executor.ts +0 -9
- package/dist/modules/api_keys/di.js +0 -9
- package/dist/modules/api_keys/di.js.map +0 -7
- package/dist/modules/api_keys/services/principalService.js +0 -31
- package/dist/modules/api_keys/services/principalService.js.map +0 -7
- package/dist/modules/attachments/lib/attachment-service.js +0 -313
- package/dist/modules/attachments/lib/attachment-service.js.map +0 -7
- package/dist/modules/auth/api/reset/validate.js +0 -55
- package/dist/modules/auth/api/reset/validate.js.map +0 -7
- package/dist/modules/auth/commands/acl.js +0 -254
- package/dist/modules/auth/commands/acl.js.map +0 -7
- package/dist/modules/auth/services/principalService.js +0 -200
- package/dist/modules/auth/services/principalService.js.map +0 -7
- package/dist/modules/auth/services/roleOrganizationScope.js +0 -41
- package/dist/modules/auth/services/roleOrganizationScope.js.map +0 -7
- package/dist/modules/communication_channels/lib/outbound-recipient.js +0 -33
- package/dist/modules/communication_channels/lib/outbound-recipient.js.map +0 -7
- package/dist/modules/communication_channels/lib/resolve-channel-type.js +0 -51
- package/dist/modules/communication_channels/lib/resolve-channel-type.js.map +0 -7
- package/dist/modules/customers/backend/customers/deals/pipeline/components/toneClasses.js +0 -18
- package/dist/modules/customers/backend/customers/deals/pipeline/components/toneClasses.js.map +0 -7
- package/dist/modules/customers/lib/calendar/participantIdentity.js +0 -9
- package/dist/modules/customers/lib/calendar/participantIdentity.js.map +0 -7
- package/dist/modules/customers/lib/closureStage.js +0 -45
- package/dist/modules/customers/lib/closureStage.js.map +0 -7
- package/dist/modules/customers/lib/detailReadAccess.js +0 -12
- package/dist/modules/customers/lib/detailReadAccess.js.map +0 -7
- package/dist/modules/data_sync/lib/abandoned-run.js +0 -19
- package/dist/modules/data_sync/lib/abandoned-run.js.map +0 -7
- package/dist/modules/devices/api/deviceSerialization.js +0 -46
- package/dist/modules/devices/api/deviceSerialization.js.map +0 -7
- package/dist/modules/directory/services/organizationHierarchyService.js +0 -29
- package/dist/modules/directory/services/organizationHierarchyService.js.map +0 -7
- package/dist/modules/directory/services/organizationScopeService.js +0 -56
- package/dist/modules/directory/services/organizationScopeService.js.map +0 -7
- package/dist/modules/integrations/backend/integrations/credential-secret-fields.js +0 -55
- package/dist/modules/integrations/backend/integrations/credential-secret-fields.js.map +0 -7
- package/dist/modules/messages/lib/channel-sender-identity.js +0 -26
- package/dist/modules/messages/lib/channel-sender-identity.js.map +0 -7
- package/dist/modules/messages/lib/composeSourceChannelType.js +0 -41
- package/dist/modules/messages/lib/composeSourceChannelType.js.map +0 -7
- package/dist/modules/query_index/lib/search-entity-policy.js +0 -14
- package/dist/modules/query_index/lib/search-entity-policy.js.map +0 -7
- package/dist/modules/sales/components/documents/lineItemShipmentLock.js +0 -54
- package/dist/modules/sales/components/documents/lineItemShipmentLock.js.map +0 -7
- package/dist/modules/sales/lib/salesChannelsToggleSeed.js +0 -33
- package/dist/modules/sales/lib/salesChannelsToggleSeed.js.map +0 -7
- package/dist/modules/sales/migrations/Migration20260821120000_sales_notes_addresses_context_idx.js +0 -32
- package/dist/modules/sales/migrations/Migration20260821120000_sales_notes_addresses_context_idx.js.map +0 -7
- package/dist/modules/wms/api/warehouseSearch.js +0 -21
- package/dist/modules/wms/api/warehouseSearch.js.map +0 -7
- package/dist/modules/wms/components/backend/WarehouseEditDialog.js +0 -158
- package/dist/modules/wms/components/backend/WarehouseEditDialog.js.map +0 -7
- package/dist/modules/wms/components/backend/warehouseFormOptions.js +0 -66
- package/dist/modules/wms/components/backend/warehouseFormOptions.js.map +0 -7
- package/src/modules/api_keys/di.ts +0 -7
- package/src/modules/api_keys/services/principalService.ts +0 -33
- package/src/modules/attachments/lib/attachment-service.ts +0 -468
- package/src/modules/auth/api/reset/validate.ts +0 -57
- package/src/modules/auth/commands/acl.ts +0 -495
- package/src/modules/auth/services/principalService.ts +0 -266
- package/src/modules/auth/services/roleOrganizationScope.ts +0 -70
- package/src/modules/communication_channels/lib/outbound-recipient.ts +0 -71
- package/src/modules/communication_channels/lib/resolve-channel-type.ts +0 -99
- package/src/modules/customers/backend/customers/deals/pipeline/components/toneClasses.ts +0 -21
- package/src/modules/customers/lib/calendar/participantIdentity.ts +0 -17
- package/src/modules/customers/lib/closureStage.ts +0 -76
- package/src/modules/customers/lib/detailReadAccess.ts +0 -35
- package/src/modules/data_sync/lib/abandoned-run.ts +0 -56
- package/src/modules/devices/api/deviceSerialization.ts +0 -50
- package/src/modules/directory/services/organizationHierarchyService.ts +0 -34
- package/src/modules/directory/services/organizationScopeService.ts +0 -85
- package/src/modules/integrations/backend/integrations/credential-secret-fields.ts +0 -84
- package/src/modules/messages/lib/channel-sender-identity.ts +0 -55
- package/src/modules/messages/lib/composeSourceChannelType.ts +0 -95
- package/src/modules/query_index/lib/search-entity-policy.ts +0 -46
- package/src/modules/sales/components/documents/lineItemShipmentLock.ts +0 -74
- package/src/modules/sales/lib/salesChannelsToggleSeed.ts +0 -42
- package/src/modules/sales/migrations/Migration20260821120000_sales_notes_addresses_context_idx.ts +0 -87
- package/src/modules/wms/api/warehouseSearch.ts +0 -23
- package/src/modules/wms/components/backend/WarehouseEditDialog.tsx +0 -216
- package/src/modules/wms/components/backend/warehouseFormOptions.ts +0 -72
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/modules/query_index/lib/engine.ts"],
|
|
4
|
-
"sourcesContent": ["import type { QueryEngine, QueryOptions, QueryResult, QueryResultMeta, EncryptedSortRowCapWarning, ListCountCapWarning, FilterOp, Filter, QueryCustomFieldSource, PartialIndexWarning, QueryExtensionsConfig, Sort } from '@open-mercato/shared/lib/query/types'\nimport { SortDir } from '@open-mercato/shared/lib/query/types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { BasicQueryEngine, resolveEntityTableName, resolveRegisteredEntityTableName } from '@open-mercato/shared/lib/query/engine'\nimport { isOrmBackedSystemEntityId } from '@open-mercato/shared/lib/data/engine'\nimport { type Kysely, sql, type RawBuilder } from 'kysely'\nimport type { EventBus } from '@open-mercato/events'\nimport { readCoverageSnapshot, refreshCoverageSnapshot } from './coverage'\nimport { createProfiler, shouldEnableProfiler, type Profiler } from '@open-mercato/shared/lib/profiler'\nimport type { VectorIndexService } from '@open-mercato/search/vector'\nimport { decryptIndexDocCustomFields } from '@open-mercato/shared/lib/encryption/indexDoc'\nimport { parseBooleanToken, parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\nimport {\n applyJoinFilters,\n normalizeFilters,\n partitionFilters,\n resolveJoins,\n type BaseFilter,\n type ResolvedJoin,\n} from '@open-mercato/shared/lib/query/join-utils'\nimport { resolveSearchConfig, type SearchConfig } from '@open-mercato/shared/lib/search/config'\nimport { isEncryptedLikeField, resolveEncryptedLikeFieldSet } from '@open-mercato/shared/lib/query/engine'\nimport { isTenantDataEncryptionEnabled } from '@open-mercato/shared/lib/encryption/toggles'\nimport {\n createSearchTokenAvailability,\n isSearchFilterOp,\n hasSearchFilter,\n type SearchTokenAvailability,\n type SearchTokenProbeDb,\n type SearchTokenProbeQueryBuilder,\n} from '@open-mercato/shared/lib/search/availability'\nimport { tokenizeText } from '@open-mercato/shared/lib/search/tokenize'\nimport { runBeforeQueryPipeline, runAfterQueryPipeline, type QueryExtensionContext } from '@open-mercato/shared/lib/query/query-extension-runner'\nimport { warnOnCiphertextLikeFallback } from '@open-mercato/shared/lib/query/ciphertext-search-warning'\nimport { resolveEncryptedSortFields, resolveEncryptedSortMaxRows, sortRowsInMemory } from '@open-mercato/shared/lib/query/encrypted-sort'\nimport { resolveListCountCap } from '@open-mercato/shared/lib/query/count-cap'\nimport { mapWithConcurrency } from '@open-mercato/shared/lib/query/bounded-decrypt'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { parseNumberWithDefault } from '@open-mercato/shared/lib/number'\n\nconst logger = createLogger('query_index').child({ component: 'engine' })\n\n/** Operators `buildCfFilterExpression` compiles; anything else yields no predicate. */\nconst CF_FILTER_SUPPORTED_OPS = new Set<FilterOp>([\n 'eq', 'ne', 'in', 'nin', 'like', 'ilike', 'exists', 'gt', 'gte', 'lt', 'lte',\n])\n\nconst DECRYPT_CONCURRENCY = 8\nconst AUTO_REINDEX_DEBOUNCE_DEFAULT_MS = 30_000\nconst AUTO_REINDEX_DEBOUNCE_MAX_SCOPES = 10_000\nconst AUTO_REINDEX_SCHEDULED_AT_KEY = Symbol.for('@open-mercato/query-index/auto-reindex-scheduled-at')\n\ntype GlobalWithAutoReindexSchedule = typeof globalThis & {\n [AUTO_REINDEX_SCHEDULED_AT_KEY]?: Map<string, number>\n}\n\nfunction getAutoReindexScheduledAt(): Map<string, number> {\n const globalScope = globalThis as GlobalWithAutoReindexSchedule\n if (!globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY]) {\n globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY] = new Map<string, number>()\n }\n return globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY]\n}\n\nfunction markAutoReindexScheduled(key: string, debounceMs: number, now: number): boolean {\n const autoReindexScheduledAt = getAutoReindexScheduledAt()\n const previous = autoReindexScheduledAt.get(key)\n if (previous !== undefined && now - previous < debounceMs) return false\n\n if (autoReindexScheduledAt.size >= AUTO_REINDEX_DEBOUNCE_MAX_SCOPES) {\n for (const [scopeKey, scheduledAt] of autoReindexScheduledAt) {\n if (now - scheduledAt >= debounceMs) autoReindexScheduledAt.delete(scopeKey)\n }\n if (autoReindexScheduledAt.size >= AUTO_REINDEX_DEBOUNCE_MAX_SCOPES) {\n const oldestKey = autoReindexScheduledAt.keys().next().value\n if (oldestKey !== undefined) autoReindexScheduledAt.delete(oldestKey)\n }\n }\n\n autoReindexScheduledAt.delete(key)\n autoReindexScheduledAt.set(key, now)\n return true\n}\n\nfunction buildFilterableCustomFieldJoins(\n sources: QueryCustomFieldSource[] | undefined,\n): Array<{\n alias: string\n table?: string\n entityId: EntityId\n from: { field: string }\n to: { field: string }\n type: 'left' | 'inner'\n}> {\n if (!sources || sources.length === 0) return []\n return sources.flatMap((source, index) => {\n if (!source.join) return []\n const alias = typeof source.alias === 'string' && source.alias.trim().length > 0\n ? source.alias.trim()\n : `cfs_${index}`\n return [{\n alias,\n table: source.table,\n entityId: source.entityId,\n from: { field: source.join.fromField },\n to: { field: source.join.toField },\n type: source.join.type === 'inner' ? 'inner' : 'left',\n }]\n })\n}\n\nfunction resolveBooleanEnv(names: readonly string[], defaultValue: boolean): boolean {\n for (const name of names) {\n const raw = process.env[name]\n if (raw !== undefined) return parseBooleanWithDefault(raw, defaultValue)\n }\n return defaultValue\n}\n\nexport function coerceSortDirection(dir: unknown): SortDir {\n return String(dir ?? SortDir.Asc).toLowerCase() === SortDir.Desc ? SortDir.Desc : SortDir.Asc\n}\n\nfunction resolveDebugVerbosity(): boolean {\n const queryIndexDebug = process.env.OM_QUERY_INDEX_DEBUG\n if (queryIndexDebug !== undefined) {\n return parseBooleanToken(queryIndexDebug) ?? false\n }\n const level = (process.env.LOG_VERBOSITY ?? process.env.LOG_LEVEL ?? '').toLowerCase()\n if (['debug', 'trace', 'silly'].includes(level)) return true\n return false\n}\n\ntype AnyDb = Kysely<any>\ntype AnyBuilder = any\ntype NormalizedFilter = { field: string; op: FilterOp; value?: unknown }\ntype IndexDocSource = { alias: string; entityId: EntityId; recordIdColumn: string }\ntype PreparedCustomFieldSource = {\n alias: string\n indexAlias: string\n entityId: EntityId\n recordIdColumn: string\n organizationField?: string\n tenantField?: string\n table: string\n}\ntype SearchRuntime = {\n enabled: boolean\n config: SearchConfig\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n tenantId?: string | null\n searchSources?: SearchTokenSource[]\n /**\n * Base-column fields whose stored value is ciphertext, so a like/ilike on them can only be\n * answered via search tokens. A plaintext column keeps exact SQL ILIKE instead: the token\n * rewrite is approximate -- it splits on non-alphanumerics and drops tokens shorter than\n * minTokenLength, so a document-number search like \"ZK 1/2026\" degrades to the tokens\n * {202, 2026} and matches every record from that year, and an all-short term like \"ZK\"\n * produces no tokens and silently drops the predicate. `null`/absent = the encryption\n * service could not answer (or a caller predates this field); keep the old rewrite then,\n * because guessing \"plaintext\" would turn encrypted-column search into an\n * ILIKE-on-ciphertext that matches nothing.\n */\n encryptedFields?: Set<string> | null\n /** Per-`query()` alias minter for `search_tokens` subqueries (see #2738). */\n mintAlias: () => string\n}\n\ntype EncryptionResolver = () => {\n decryptEntityPayload?: (entityId: EntityId, payload: Record<string, unknown>, tenantId?: string | null, organizationId?: string | null) => Promise<Record<string, unknown>>\n getEncryptedFieldNames?: (entityId: EntityId, tenantId?: string | null, organizationId?: string | null, options?: { ignoreRuntimeHealth?: boolean }) => Promise<readonly string[]>\n isEnabled?: () => boolean\n} | null\n\ntype SearchTokenSource = { entity: string; recordIdColumn: string }\n\n/**\n * Mints `search_tokens` subquery aliases (`st_0`, `st_1`, \u2026). Aliases only need\n * to be unique within a single SQL statement, so every `query()` invocation owns\n * a fresh minter. Keeping the counter call-local (rather than on the shared\n * engine instance) means concurrent queries can never reset or collide on each\n * other's sequence (#2738).\n */\nfunction createSearchAliasMinter(): () => string {\n let seq = 0\n return () => `st_${seq++}`\n}\n\nfunction createQueryProfiler(entity: string): Profiler {\n const enabled = shouldEnableProfiler(entity)\n return createProfiler({\n scope: 'query_engine',\n target: entity,\n label: `query_engine:${entity}`,\n loggerLabel: '[qe:profile]',\n enabled,\n })\n}\n\nexport class HybridQueryEngine implements QueryEngine {\n private coverageStatsTtlMs: number\n private customFieldKeysCache = new Map<string, { expiresAt: number; value: string[] }>()\n private customFieldKeysTtlMs: number\n private columnCache = new Map<string, boolean>()\n private customEntityCache = new Map<string, boolean>()\n private debugVerbosity: boolean | null = null\n private sqlDebugEnabled: boolean | null = null\n private forcePartialIndexEnabled: boolean | null = null\n private autoReindexEnabled: boolean | null = null\n private autoReindexDebounceMs: number | null = null\n private coverageOptimizationEnabled: boolean | null = null\n private pendingCoverageRefreshKeys = new Set<string>()\n private searchAvailabilityInstance: SearchTokenAvailability | null = null\n\n constructor(\n private em: EntityManager,\n private fallback: BasicQueryEngine,\n private eventBusResolver?: () => Pick<EventBus, 'emitEvent'> | null | undefined,\n private vectorServiceResolver?: () => VectorIndexService | null | undefined,\n private encryptionResolver?: EncryptionResolver,\n ) {\n const coverageTtl = Number.parseInt(process.env.QUERY_INDEX_COVERAGE_CACHE_MS ?? '', 10)\n this.coverageStatsTtlMs = Number.isFinite(coverageTtl) && coverageTtl >= 0 ? coverageTtl : 5 * 60 * 1000\n const cfTtl = Number.parseInt(process.env.QUERY_INDEX_CF_KEYS_CACHE_MS ?? '', 10)\n this.customFieldKeysTtlMs = Number.isFinite(cfTtl) && cfTtl >= 0 ? cfTtl : 5 * 60 * 1000\n }\n\n private getEncryptionService() {\n try {\n return this.encryptionResolver?.() ?? null\n } catch {\n return null\n }\n }\n\n private getDb(): AnyDb {\n const emAny = this.em as any\n if (typeof emAny.getKysely === 'function') return emAny.getKysely() as AnyDb\n throw new Error('HybridQueryEngine requires an EntityManager exposing getKysely() (MikroORM v7)')\n }\n\n private searchAvailability(): SearchTokenAvailability {\n if (!this.searchAvailabilityInstance) {\n this.searchAvailabilityInstance = createSearchTokenAvailability({\n getDb: () => this.getDb() as unknown as SearchTokenProbeDb,\n getConfig: resolveSearchConfig,\n applyOrganizationScope: (query, column, scope) => this.applyOrganizationScope(\n query as unknown as AnyBuilder,\n column,\n scope,\n ) as unknown as SearchTokenProbeQueryBuilder,\n logDebug: (event, payload) => this.logSearchDebug(event, payload),\n })\n }\n return this.searchAvailabilityInstance\n }\n\n async query<T = unknown>(entity: EntityId, opts: QueryOptions = {}): Promise<QueryResult<T>> {\n const ext: QueryExtensionsConfig | undefined = opts.extensions\n let hybridExtCtx: QueryExtensionContext | null = null\n const noopDi = { resolve: <R = unknown>(_name: string): R => { throw new Error('No DI context') } }\n\n if (ext) {\n hybridExtCtx = {\n entity: String(entity),\n engine: 'hybrid',\n tenantId: opts.tenantId ?? '',\n organizationId: opts.organizationId,\n userId: ext.userId,\n em: this.em,\n container: ext.container,\n userFeatures: ext.userFeatures,\n }\n const diCtx = ext.resolve ? { resolve: ext.resolve } : noopDi\n const beforeResult = await runBeforeQueryPipeline(opts, hybridExtCtx, diCtx)\n if (beforeResult.blocked) {\n throw new Error(beforeResult.errorMessage ?? 'Query blocked by extension subscriber')\n }\n opts = beforeResult.query\n }\n const { extensions: _stripExt, ...coreOpts } = opts\n opts = coreOpts\n\n const providedProfiler = opts.profiler\n const profiler = providedProfiler && providedProfiler.enabled\n ? providedProfiler\n : createQueryProfiler(String(entity))\n profiler.mark('query:init')\n let profileClosed = false\n const finishProfile = (meta?: Record<string, unknown>) => {\n if (!profiler.enabled || profileClosed) return\n profileClosed = true\n profiler.end(meta)\n }\n\n const applyAfterExtensions = async <R>(queryResult: QueryResult<R>): Promise<QueryResult<R>> => {\n if (!ext || !hybridExtCtx) return queryResult\n const diCtx = ext.resolve ? { resolve: ext.resolve } : noopDi\n return await runAfterQueryPipeline(\n queryResult as QueryResult<Record<string, unknown>>,\n opts,\n hybridExtCtx,\n diCtx,\n ) as QueryResult<R>\n }\n\n try {\n const debugEnabled = this.isDebugVerbosity()\n if (debugEnabled) this.debug('query:start', { entity })\n\n const isCustom = opts.forceCustomEntityStorage === true || await this.isCustomEntity(entity)\n if (isCustom) {\n if (debugEnabled) this.debug('query:custom-entity', { entity })\n const section = profiler.section('custom_entity')\n try {\n const result = await this.queryCustomEntity<T>(entity, opts)\n section.end({ mode: 'custom_entity' })\n finishProfile({\n result: 'custom_entity',\n total: Array.isArray(result.items) ? result.items.length : undefined,\n })\n return await applyAfterExtensions(result)\n } catch (err) {\n section.end({ error: err instanceof Error ? err.message : String(err) })\n throw err\n }\n }\n\n const db = this.getDb()\n profiler.mark('query:db_ready')\n const baseTable = resolveEntityTableName(this.em, entity)\n profiler.mark('query:base_table_resolved')\n const searchConfig = resolveSearchConfig()\n const orgScope = this.resolveOrganizationScope(opts)\n const searchEnabled = await this.searchAvailability().staticEnabled()\n\n const baseExists = await profiler.measure('base_table_exists', () => this.tableExists(baseTable))\n if (!baseExists) {\n if (debugEnabled) this.debug('query:fallback:missing-base', { entity, baseTable })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'missing_base' })\n return await applyAfterExtensions(fallbackResult)\n }\n\n if (opts.omitAutomaticTenantOrgScope === true) {\n if (debugEnabled) this.debug('query:fallback:omit-automatic-scope', { entity })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'omit_automatic_tenant_org_scope' })\n return await applyAfterExtensions(fallbackResult)\n }\n\n const normalizedFilters = normalizeFilters(opts.filters)\n const cfFilters = normalizedFilters.filter((filter) => filter.field.startsWith('cf:') || filter.field.startsWith('l10n:'))\n const coverageScope = this.resolveCoverageSnapshotScope(opts)\n const wantsCf = (\n (opts.fields || []).some((field) => typeof field === 'string' && (field.startsWith('cf:') || field.startsWith('l10n:'))) ||\n cfFilters.length > 0 ||\n (Array.isArray(opts.includeCustomFields) && opts.includeCustomFields.length > 0)\n )\n\n if (debugEnabled) {\n this.debug('query:config', {\n entity,\n wantsCustomFields: wantsCf,\n customFieldSources: Array.isArray(opts.customFieldSources) ? opts.customFieldSources.map((src) => src?.entityId) : undefined,\n fields: opts.fields,\n })\n }\n\n let partialIndexWarning: PartialIndexWarning | null = null\n let entityHasActiveCustomFields = true\n\n if (wantsCf) {\n entityHasActiveCustomFields = await this.entityHasActiveCustomFields(entity, opts.tenantId ?? null)\n const hasIndexRows = await profiler.measure(\n 'index_any_rows',\n () => this.indexAnyRows(entity),\n (value) => ({ hasIndexRows: value })\n )\n if (!hasIndexRows) {\n if (debugEnabled) this.debug('query:fallback:no-index', { entity })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'no_index_rows' })\n return await applyAfterExtensions(fallbackResult)\n }\n if (entityHasActiveCustomFields) {\n const gap = await profiler.measure(\n 'resolve_coverage_gap',\n () => this.resolveCoverageGap(entity, opts, coverageScope),\n (value) => (value\n ? {\n scope: value.scope,\n baseCount: value.stats?.baseCount ?? null,\n indexedCount: value.stats?.indexedCount ?? null,\n }\n : { scope: null })\n )\n if (gap) {\n if (!opts.skipAutoReindex) {\n this.scheduleAutoReindex(entity, opts, gap.stats, coverageScope?.organizationId ?? null)\n }\n const force = this.isForcePartialIndexEnabled()\n if (!force) {\n if (gap.stats) {\n logger.warn('Partial index coverage detected; falling back to basic engine', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n if (debugEnabled) this.debug('query:fallback:partial-coverage', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n } else {\n logger.warn('Partial index coverage detected; falling back to basic engine', { entity })\n if (debugEnabled) this.debug('query:fallback:partial-coverage', { entity })\n }\n const fallbackResult = await this.fallback.query(entity, opts)\n const resultWithWarning: QueryResult<T> = {\n ...fallbackResult,\n meta: {\n ...(fallbackResult.meta ?? {}),\n partialIndexWarning: {\n entity,\n entityLabel: this.resolveEntityLabel(entity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n },\n },\n }\n finishProfile({\n result: 'fallback',\n reason: 'partial_index',\n scope: gap.scope,\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n })\n return await applyAfterExtensions(resultWithWarning)\n }\n if (gap.stats) {\n logger.warn('Partial index coverage detected; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n } else {\n logger.warn('Partial index coverage detected; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity })\n }\n partialIndexWarning = {\n entity,\n entityLabel: this.resolveEntityLabel(entity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n }\n }\n } else if (debugEnabled) {\n this.debug('query:coverage:skip-no-custom-fields', { entity })\n }\n }\n\n const qualify = (col: string) => `b.${col}`\n const columns = await this.getBaseColumnsForEntity(entity)\n const hasOrganizationColumn = await this.columnExists(baseTable, 'organization_id')\n const hasTenantColumn = await this.columnExists(baseTable, 'tenant_id')\n const hasDeletedColumn = await this.columnExists(baseTable, 'deleted_at')\n\n if (!opts.tenantId) throw new Error('QueryEngine: tenantId is required')\n\n const resolvedJoinsConfig = resolveJoins(\n baseTable,\n [...(opts.joins ?? []), ...buildFilterableCustomFieldJoins(opts.customFieldSources)],\n (entityId) => resolveEntityTableName(this.em, entityId as any),\n )\n const joinMap = new Map<string, ResolvedJoin>()\n const aliasTables = new Map<string, string>()\n aliasTables.set('b', baseTable)\n aliasTables.set('base', baseTable)\n aliasTables.set(baseTable, baseTable)\n for (const join of resolvedJoinsConfig) {\n joinMap.set(join.alias, join)\n aliasTables.set(join.alias, join.table)\n }\n const { baseFilters, joinFilters } = partitionFilters(baseTable, normalizedFilters, joinMap)\n\n const searchRuntimeBase = {\n enabled: false,\n config: searchConfig,\n organizationScope: orgScope,\n tenantId: opts.tenantId ?? null,\n mintAlias: createSearchAliasMinter(),\n }\n\n // Prepare index sources for JSONB custom-field access.\n const indexSources: IndexDocSource[] = [{ alias: 'ei', entityId: entity, recordIdColumn: 'b.id' }]\n let preparedCfSources: PreparedCustomFieldSource[] = []\n const shouldAttachCustomSources = Array.isArray(opts.customFieldSources) && opts.customFieldSources.length > 0 && (wantsCf || searchEnabled)\n if (shouldAttachCustomSources) {\n preparedCfSources = this.prepareCustomFieldSources(opts.customFieldSources ?? [])\n for (const source of preparedCfSources) {\n indexSources.push({ alias: source.indexAlias, entityId: source.entityId, recordIdColumn: `${source.alias}.${source.recordIdColumn}` })\n }\n }\n\n const searchSources: SearchTokenSource[] = indexSources\n .map((src) => ({ entity: String(src.entityId), recordIdColumn: src.recordIdColumn }))\n .filter((src) => src.recordIdColumn && src.entity)\n const searchFilters = normalizedFilters.filter((filter) => isSearchFilterOp(filter.op))\n const sourceSearchFilters = [\n ...baseFilters,\n ...normalizedFilters.filter((filter) => String(filter.field).startsWith('cf:')),\n ].filter((filter) => isSearchFilterOp(filter.op))\n // Probe `search_tokens` only when this query actually searches (#4723). Every consumer of\n // `searchRuntime.enabled` already sits behind a like/ilike guard, so on a plain list load the\n // answer is unused \u2014 and the probe is a `LIMIT 1` the planner can resolve as a seq scan over a\n // large `search_tokens`. The join path below already probes lazily for the same reason.\n const hasSearchTokens = searchEnabled && searchSources.length && sourceSearchFilters.length\n ? await this.searchAvailability().anySourceHasTokens(searchSources, opts.tenantId ?? null, orgScope)\n : false\n const searchRuntime: SearchRuntime = { ...searchRuntimeBase, searchSources, enabled: searchEnabled && hasSearchTokens }\n if (\n searchRuntime.enabled &&\n searchConfig.useIlikeForNonEncryptedFields === true &&\n sourceSearchFilters.some((filter) => !String(filter.field).startsWith('cf:'))\n ) {\n // `ignoreRuntimeHealth` asks the on-disk question -- a column holds ciphertext even while\n // the KMS is down -- so an outage keeps encrypted columns on the token path (#4622).\n // `organizationId: null` is deliberate, not an omission: the service then unions in every\n // organization's map (`fetchAllOrganizationFieldNames`), so a field any org encrypts stays\n // on the token path -- a wider set fails safe. Passing the request's org instead would\n // silently break encrypted-column search for orgs without their own map. That union is an\n // UNCACHED `encryption_maps` read, one extra round-trip per searched list request.\n try {\n const encryptionService = this.getEncryptionService()\n const readEncryptedFieldNames = encryptionService?.getEncryptedFieldNames?.bind(encryptionService)\n if (readEncryptedFieldNames) {\n searchRuntime.encryptedFields = await resolveEncryptedLikeFieldSet(\n () => readEncryptedFieldNames(\n entity as EntityId,\n opts.tenantId ?? null,\n null,\n { ignoreRuntimeHealth: true },\n ),\n String(entity),\n opts.tenantId ?? null,\n )\n } else if (isTenantDataEncryptionEnabled()) {\n // Encryption is on but the service is unreachable (a swallowed DI failure looks\n // exactly like \"no service\"): treat the map as UNKNOWN and keep the token rewrite,\n // rather than guessing \"plaintext\" and running ILIKE against ciphertext.\n searchRuntime.encryptedFields = null\n } else {\n // Encryption disabled: nothing is ciphertext at rest, exact ILIKE is always right.\n searchRuntime.encryptedFields = new Set()\n }\n } catch (err) {\n // The fallback is safe (the old rewrite-everything behavior), but taking it silently\n // would hide that the gate has stopped working.\n logger.warn('search: encrypted-field map unavailable; keeping the token rewrite for all columns', {\n entity: String(entity),\n error: err instanceof Error ? err.message : String(err),\n })\n searchRuntime.encryptedFields = null\n }\n }\n if (searchFilters.length) {\n this.logSearchDebug('search:init', {\n entity,\n baseTable,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n fields: searchFilters.map((filter) => String(filter.field)),\n searchEnabled,\n hasSearchTokens,\n searchSources,\n searchConfig: {\n enabled: searchConfig.enabled,\n minTokenLength: searchConfig.minTokenLength,\n enablePartials: searchConfig.enablePartials,\n hashAlgorithm: searchConfig.hashAlgorithm,\n blocklistedFields: searchConfig.blocklistedFields,\n },\n })\n if (!searchEnabled) this.logSearchDebug('search:disabled', { entity, baseTable })\n else if (!hasSearchTokens) this.logSearchDebug('search:no-search-tokens', {\n entity, baseTable,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n searchSources,\n })\n const baseSearchFilters = [...baseFilters, ...cfFilters]\n .filter((filter) => filter.op === 'like' || filter.op === 'ilike')\n const fallbackFields = baseSearchFilters\n .filter((filter) => !searchRuntime.enabled || typeof filter.value !== 'string' || tokenizeText(filter.value, searchConfig).hashes.length === 0)\n .map((filter) => String(filter.field))\n if (fallbackFields.length) {\n await warnOnCiphertextLikeFallback({\n entity: String(entity),\n fields: fallbackFields,\n tenantId: opts.tenantId ?? null,\n // `searchEnabled` also folds in the missing-table case, which is\n // \"no usable tokens\" rather than \"the operator switched search off\".\n reason: searchRuntime.enabled\n ? 'no-indexable-tokens'\n : searchConfig.enabled ? 'no-search-tokens' : 'search-disabled',\n service: this.getEncryptionService(),\n })\n }\n }\n for (const [alias, joinedFilters] of joinFilters) {\n const filters = joinedFilters.filter((entry) => entry.op === 'like' || entry.op === 'ilike')\n if (!filters.length) continue\n const join = joinMap.get(alias)\n if (!join?.entityId) continue\n const hasJoinedTokens = searchEnabled\n ? await this.searchAvailability().hasTokens(String(join.entityId), opts.tenantId ?? null, orgScope)\n : false\n const fallbackFields = filters\n .filter((filter) => !hasJoinedTokens || typeof filter.value !== 'string' || tokenizeText(filter.value, searchConfig).hashes.length === 0)\n .map((filter) => filter.column)\n if (!fallbackFields.length) continue\n await warnOnCiphertextLikeFallback({\n entity: String(join.entityId),\n fields: fallbackFields,\n tenantId: opts.tenantId ?? null,\n reason: hasJoinedTokens\n ? 'no-indexable-tokens'\n : searchConfig.enabled ? 'no-search-tokens' : 'search-disabled',\n service: this.getEncryptionService(),\n })\n }\n const hasNonBaseSearchSource = searchSources.some(\n (src) => src.entity !== String(entity) || src.recordIdColumn !== 'b.id'\n )\n\n // Additional partial-coverage checks for customFieldSources\n if (!partialIndexWarning && Array.isArray(opts.customFieldSources) && opts.customFieldSources.length > 0 && this.isForcePartialIndexEnabled()) {\n const seen = new Set<string>([entity])\n for (const source of opts.customFieldSources) {\n const targetEntity = source?.entityId ? String(source.entityId) : null\n if (!targetEntity || seen.has(targetEntity)) continue\n seen.add(targetEntity)\n const sourceHasCustomFields = await this.entityHasActiveCustomFields(targetEntity, opts.tenantId ?? null)\n if (!sourceHasCustomFields) {\n if (debugEnabled) this.debug('query:coverage:skip-no-custom-fields', { entity: targetEntity })\n continue\n }\n const sourceTable = source.table ?? resolveEntityTableName(this.em, targetEntity)\n try {\n const gap = await profiler.measure(\n 'resolve_coverage_gap',\n () => this.resolveCoverageGap(targetEntity, opts, coverageScope, sourceTable),\n (value) => (value\n ? {\n entity: targetEntity, scope: value.scope,\n baseCount: value.stats?.baseCount ?? null,\n indexedCount: value.stats?.indexedCount ?? null,\n }\n : { entity: targetEntity, scope: null })\n )\n if (!gap) continue\n if (!opts.skipAutoReindex) {\n this.scheduleAutoReindex(targetEntity, opts, gap.stats, coverageScope?.organizationId ?? null)\n }\n partialIndexWarning = {\n entity: targetEntity,\n entityLabel: this.resolveEntityLabel(targetEntity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n }\n if (debugEnabled) {\n if (gap.stats) this.debug('query:partial-coverage:forced', { entity: targetEntity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n else this.debug('query:partial-coverage:forced', { entity: targetEntity })\n }\n break\n } catch (err) {\n if (debugEnabled) this.debug('query:partial-coverage:check-failed', { entity: targetEntity, error: err instanceof Error ? err.message : err })\n }\n }\n }\n\n if (\n !partialIndexWarning &&\n wantsCf &&\n entityHasActiveCustomFields &&\n this.isForcePartialIndexEnabled() &&\n opts.tenantId\n ) {\n try {\n await this.indexCoverageStats(entity, opts, coverageScope)\n const globalStats = await this.indexCoverageStats(entity, opts, coverageScope)\n if (globalStats) {\n const globalBase = globalStats.baseCount\n const globalIndexed = globalStats.indexedCount\n const globalGap = (globalBase > 0 && globalIndexed < globalBase) || globalIndexed > globalBase\n if (globalGap) {\n logger.warn('Partial index coverage detected at global scope; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity, baseCount: globalBase, indexedCount: globalIndexed, scope: 'global' })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity, baseCount: globalBase, indexedCount: globalIndexed, scope: 'global' })\n partialIndexWarning = {\n entity, entityLabel: this.resolveEntityLabel(entity),\n baseCount: globalBase, indexedCount: globalIndexed, scope: 'global',\n }\n }\n }\n } catch (err) {\n if (debugEnabled) this.debug('query:partial-coverage:global-check-failed', { entity, error: err instanceof Error ? err.message : err })\n }\n }\n\n const resolveBaseColumn = (field: string): string | null => {\n if (columns.has(field)) return field\n if (field === 'organization_id' && columns.has('id')) return 'id'\n return null\n }\n const fallbackOrgId =\n opts.organizationId\n ?? (Array.isArray(opts.organizationIds) && opts.organizationIds.length === 1 ? opts.organizationIds[0] : null)\n const encSvc = this.getEncryptionService()\n const resolvedSorts: Sort[] = []\n for (const sort of opts.sort || []) {\n const field = String(sort.field)\n if (field.startsWith('cf:')) {\n resolvedSorts.push({ ...sort, field })\n } else {\n const baseField = resolveBaseColumn(field)\n if (baseField) resolvedSorts.push({ ...sort, field: baseField })\n }\n }\n const encryptedSortFields = await resolveEncryptedSortFields(\n encSvc,\n entity,\n resolvedSorts.filter((sort) => !sort.field.startsWith('cf:')).map((sort) => sort.field),\n opts.tenantId ?? null,\n fallbackOrgId,\n )\n const requiresPlaintextSort = encryptedSortFields.size > 0\n\n // \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n // Build a reusable \"applyQueryShape\" function that applies every\n // WHERE/JOIN/scope to a fresh SelectQueryBuilder. We use this in\n // place of knex's `.clone()` for producing count + data queries.\n // \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n const applyBaseScope = (q: AnyBuilder): AnyBuilder => {\n let next = q\n if (orgScope && hasOrganizationColumn) {\n next = this.applyOrganizationScope(next, qualify('organization_id'), orgScope)\n }\n if (hasTenantColumn) {\n next = next.where(qualify('tenant_id'), '=', opts.tenantId)\n }\n if (!opts.withDeleted && hasDeletedColumn) {\n next = next.where(qualify('deleted_at'), 'is', null)\n }\n return next\n }\n\n const applyEntityIndexesJoin = (q: AnyBuilder): AnyBuilder => {\n return q.leftJoin('entity_indexes as ei', (jb: any) => {\n let jc = jb\n .on('ei.entity_type', '=', String(entity))\n .onRef('ei.entity_id', '=', sql<string>`(${sql.ref(qualify('id'))}::text)`)\n if (hasOrganizationColumn) {\n jc = jc\n .onRef('ei.organization_id', '=', qualify('organization_id'))\n .on('ei.organization_id', 'is not', null)\n }\n if (hasTenantColumn) {\n jc = jc\n .onRef('ei.tenant_id', '=', qualify('tenant_id'))\n .on('ei.tenant_id', 'is not', null)\n }\n if (!opts.withDeleted) {\n jc = jc.on('ei.deleted_at', 'is', null)\n }\n return jc\n })\n }\n\n const applyCustomFieldSourceJoins = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const source of preparedCfSources) {\n const join = (opts.customFieldSources ?? []).find((s) => s && (s.alias ?? undefined) === source.alias)?.join\n if (!join) continue\n const joinType = (join.type ?? 'left') === 'inner' ? 'innerJoin' : 'leftJoin'\n next = (next as any)[joinType](`${source.table} as ${source.alias}`, (jb: any) =>\n jb.onRef(`${source.alias}.${join.toField}`, '=', qualify(join.fromField)))\n // Index join for source\n next = next.leftJoin(`entity_indexes as ${source.indexAlias}`, (jb: any) => {\n let jc = jb\n .on(`${source.indexAlias}.entity_type`, '=', String(source.entityId))\n .onRef(`${source.indexAlias}.entity_id`, '=', sql<string>`(${sql.ref(`${source.alias}.${source.recordIdColumn}`)}::text)`)\n const orgRef = source.organizationField\n ? `${source.alias}.${source.organizationField}`\n : (columns.has('organization_id') ? qualify('organization_id') : null)\n if (orgRef) {\n jc = jc\n .onRef(`${source.indexAlias}.organization_id`, '=', orgRef)\n .on(`${source.indexAlias}.organization_id`, 'is not', null)\n }\n const tenantRef = source.tenantField\n ? `${source.alias}.${source.tenantField}`\n : (columns.has('tenant_id') ? qualify('tenant_id') : null)\n if (tenantRef) {\n jc = jc\n .onRef(`${source.indexAlias}.tenant_id`, '=', tenantRef)\n .on(`${source.indexAlias}.tenant_id`, 'is not', null)\n }\n if (!opts.withDeleted) jc = jc.on(`${source.indexAlias}.deleted_at`, 'is', null)\n return jc\n })\n }\n return next\n }\n\n // Custom-field leaves that belong to an OR disjunct are handled together with\n // the base ones below; applying them here would AND them onto every disjunct.\n const regularCfFilters = cfFilters.filter((filter) => !filter.orGroup)\n const orGroupCfFilters = cfFilters.filter((filter) => filter.orGroup)\n\n const applyCfFilters = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const filter of regularCfFilters) {\n next = this.applyCfFilterAcrossSources(\n next, filter.field, filter.op, filter.value, indexSources, searchRuntime,\n )\n }\n return next\n }\n\n const regularBaseFilters = baseFilters.filter((filter) => !filter.orGroup)\n const orGroupFilters = baseFilters.filter((filter) => filter.orGroup)\n\n const applyRegularBaseFilters = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const filter of regularBaseFilters) {\n const fieldName = String(filter.field)\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) {\n next = this.applyIndexDocFilterFromAlias(\n next, 'ei', entity, fieldName, filter.op, filter.value, 'b.id', searchRuntime,\n )\n continue\n }\n const column = qualify(baseField)\n next = this.applyColumnFilter(next, column, filter, {\n ...searchRuntime,\n entity, field: fieldName, recordIdColumn: 'b.id',\n })\n }\n return next\n }\n\n // Also used by the count shape: cf leaves (and doc-based base leaves) reference\n // the index rowset aliases, so any group containing one routes the whole\n // disjunction inside the seeded-rowset EXISTS, where those aliases exist.\n const applyOrGroupedBaseFilters = (q: AnyBuilder): AnyBuilder => {\n if (orGroupFilters.length === 0 && orGroupCfFilters.length === 0) return q\n // `BaseFilter` here is just the normalized-leaf shape; the `cf` bucket holds\n // custom-field leaves, which never resolve to a base column.\n const groups = new Map<string, { base: BaseFilter[]; cf: BaseFilter[] }>()\n const bucketFor = (orGroup: string) => {\n const existing = groups.get(orGroup) ?? { base: [], cf: [] }\n groups.set(orGroup, existing)\n return existing\n }\n for (const filter of orGroupFilters) {\n if (!filter.orGroup) continue\n bucketFor(filter.orGroup).base.push(filter)\n }\n // Custom-field leaves belong to the same disjunct as the base ones sharing\n // their orGroup, so a mixed `base OR cf` filter unites rather than intersects.\n for (const filter of orGroupCfFilters) {\n if (!filter.orGroup) continue\n bucketFor(filter.orGroup).cf.push(filter)\n }\n // A cf leaf that compiles to no predicate is dropped, and a disjunct left with\n // no leaves is dropped too \u2014 an empty AND would read as TRUE and widen the result.\n const applicableGroups = Array.from(groups.values())\n .map((group) => ({\n base: group.base,\n cf: group.cf.filter((filter) =>\n this.cfFilterHasPredicate(filter.op, filter.value, indexSources, searchRuntime),\n ),\n }))\n .filter((group) => group.base.length > 0 || group.cf.length > 0)\n if (applicableGroups.length === 0) return q\n // Combine all groups in a single WHERE: disjuncts are OR'd together; within\n // each disjunct, fields are AND'd. Building this as separate `.where()` calls\n // would AND the disjuncts (wrong semantics).\n return q.where((eb: any) => {\n const disjuncts = applicableGroups.map((groupFilters) => {\n const parts = [\n ...groupFilters.base.map((filter) =>\n this.buildBaseFilterExpression(eb, filter, resolveBaseColumn, qualify, entity, searchRuntime),\n ),\n ...groupFilters.cf.map((filter) =>\n this.buildCfFilterExpression(\n eb, filter.field, filter.op, filter.value, indexSources, searchRuntime,\n ),\n ),\n ]\n return parts.length === 1 ? parts[0] : eb.and(parts)\n })\n return disjuncts.length === 1 ? disjuncts[0] : eb.or(disjuncts)\n })\n }\n\n const applyAliasScopes = async (target: AnyBuilder, aliasName: string): Promise<AnyBuilder> => {\n let next = target\n const tableName = aliasTables.get(aliasName)\n if (!tableName) return next\n if (orgScope && await this.columnExists(tableName, 'organization_id')) {\n next = this.applyOrganizationScope(next, `${aliasName}.organization_id`, orgScope)\n }\n if (opts.tenantId && await this.columnExists(tableName, 'tenant_id')) {\n next = next.where(`${aliasName}.tenant_id`, '=', opts.tenantId)\n }\n if (!opts.withDeleted && await this.columnExists(tableName, 'deleted_at')) {\n next = next.where(`${aliasName}.deleted_at`, 'is', null)\n }\n return next\n }\n\n const applyJoinFilterOpFn = (target: AnyBuilder, column: string, op: FilterOp, value?: unknown): AnyBuilder => {\n switch (op) {\n case 'eq':\n return value === null\n ? target.where(column, 'is', null)\n : target.where(column, '=', value as any)\n case 'ne':\n return value === null\n ? target.where(column, 'is not', null)\n : target.where(column, '!=', value as any)\n case 'gt': return target.where(column, '>', value as any)\n case 'gte': return target.where(column, '>=', value as any)\n case 'lt': return target.where(column, '<', value as any)\n case 'lte': return target.where(column, '<=', value as any)\n case 'in': return target.where(column, 'in', this.toArray(value))\n case 'nin': return target.where(column, 'not in', this.toArray(value))\n case 'like': return target.where(column, 'like', value as any)\n case 'ilike': return target.where(column, 'ilike', value as any)\n case 'exists': return value ? target.where(column, 'is not', null) : target.where(column, 'is', null)\n default: return target\n }\n }\n\n const applyJoinSearchFilterOp = async (\n target: AnyBuilder,\n filter: { column: string; op: FilterOp; value?: unknown },\n _qualified: string,\n join: ResolvedJoin,\n ): Promise<boolean> => {\n if (!searchEnabled || !join.entityId) return false\n if (!['like', 'ilike'].includes(filter.op)) return false\n if (typeof filter.value !== 'string' || filter.value.trim().length === 0) return false\n\n const searchAvailable = await this.searchAvailability().hasTokens(String(join.entityId), opts.tenantId ?? null, orgScope)\n if (!searchAvailable) return false\n\n const tokens = tokenizeText(String(filter.value), searchConfig)\n if (!tokens.hashes.length) return false\n\n return this.applySearchTokens(target, {\n entity: String(join.entityId),\n field: filter.column,\n hashes: tokens.hashes,\n recordIdColumn: `${join.alias}.id`,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n mintAlias: searchRuntime.mintAlias,\n })\n }\n\n const applyQueryShape = async (q: AnyBuilder): Promise<AnyBuilder> => {\n let next = applyBaseScope(q)\n next = applyEntityIndexesJoin(next)\n next = applyCustomFieldSourceJoins(next)\n next = applyCfFilters(next)\n next = applyRegularBaseFilters(next)\n next = applyOrGroupedBaseFilters(next)\n // applyJoinFilters is the shared helper that handles `joinFilters` (ALIAS:col -> value).\n next = await applyJoinFilters({\n db,\n baseTable,\n builder: next,\n joinMap,\n joinFilters,\n aliasTables,\n qualifyBase: (column) => qualify(column),\n applyAliasScope: async (target: any, alias: string) => applyAliasScopes(target as AnyBuilder, alias),\n applyFilterOp: (target, column, op, value) => applyJoinFilterOpFn(target as AnyBuilder, column, op, value),\n applyJoinFilterOp: async (target, filter, qualified, join) => {\n const applied = await applyJoinSearchFilterOp(target as AnyBuilder, filter, qualified, join)\n return { applied, builder: target }\n },\n columnExists: (tbl, column) => this.columnExists(tbl, column),\n })\n return next\n }\n\n const hasCustomFieldFilters = cfFilters.length > 0\n const canOptimizeCount = !hasCustomFieldFilters && !hasNonBaseSearchSource\n\n // \u2500\u2500 Count shape (#4552 Phase 2) \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n // The count query is rebuilt rather than derived from the display shape:\n // base scope + filters only. Predicates that read the left-joined index\n // rowset (cf filters, doc filters, or-groups with doc members, token\n // searches over joined sources) evaluate against the *same* rowset as the\n // display query, but confined inside a single correlated EXISTS built\n // from a one-row seed \u2014 so the per-base-row rowset is identical, yet a\n // semi-join cannot multiply base rows. The count therefore needs no\n // DISTINCT or GROUP BY, and an outer LIMIT actually bounds the scan (no\n // blocking aggregate between the LIMIT and the scan).\n const isRowsetDependentFilter = (filter: BaseFilter): boolean => {\n const baseField = resolveBaseColumn(String(filter.field))\n if (!baseField) return true\n // Token search may probe joined sources' record ids, which only exist\n // on the index rowset.\n if (\n (filter.op === 'like' || filter.op === 'ilike') &&\n searchRuntime.enabled &&\n typeof filter.value === 'string' &&\n hasNonBaseSearchSource\n ) return true\n return false\n }\n const rowsetRegularFilters = regularBaseFilters.filter((filter) => isRowsetDependentFilter(filter))\n const outerRegularFilters = regularBaseFilters.filter((filter) => !isRowsetDependentFilter(filter))\n // Or-groups are disjuncts of one $or, so they cannot be split between the\n // outer query and the rowset \u2014 one doc-dependent member moves them all in.\n const orGroupsRowsetDependent =\n orGroupCfFilters.length > 0 ||\n orGroupFilters.some((filter) => isRowsetDependentFilter(filter))\n const hasInnerTypedCfSource = preparedCfSources.some((source) =>\n ((opts.customFieldSources ?? []).find((s) => s && (s.alias ?? undefined) === source.alias)?.join?.type ?? 'left') === 'inner')\n const needsIndexRowset =\n hasCustomFieldFilters ||\n rowsetRegularFilters.length > 0 ||\n orGroupsRowsetDependent ||\n hasInnerTypedCfSource\n\n const applyCountShape = async (q: AnyBuilder): Promise<AnyBuilder> => {\n let next = applyBaseScope(q)\n for (const filter of outerRegularFilters) {\n const baseField = resolveBaseColumn(String(filter.field))\n if (!baseField) continue\n next = this.applyColumnFilter(next, qualify(baseField), filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: qualify('id'),\n })\n }\n if (!orGroupsRowsetDependent) next = applyOrGroupedBaseFilters(next)\n if (needsIndexRowset) {\n // One seed row per base row, then the display query's own join\n // builders \u2014 the rowset inside the EXISTS is the display rowset.\n // Built from `db` (not the where-callback's expression builder),\n // matching applyJoinFilters' detached-subquery idiom; correlated\n // references to the outer base alias resolve at compile time.\n let rowset: AnyBuilder = db\n .selectFrom(sql`(select 1)`.as('om_count_seed'))\n .select(sql<number>`1`.as('one'))\n rowset = applyEntityIndexesJoin(rowset)\n rowset = applyCustomFieldSourceJoins(rowset)\n rowset = applyCfFilters(rowset)\n for (const filter of rowsetRegularFilters) {\n const baseField = resolveBaseColumn(String(filter.field))\n if (!baseField) {\n rowset = this.applyIndexDocFilterFromAlias(\n rowset, 'ei', entity, String(filter.field), filter.op, filter.value, qualify('id'), searchRuntime,\n )\n continue\n }\n rowset = this.applyColumnFilter(rowset, qualify(baseField), filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: qualify('id'),\n })\n }\n if (orGroupsRowsetDependent) rowset = applyOrGroupedBaseFilters(rowset)\n const capturedRowset = rowset\n next = next.where((eb: any) => eb.exists(capturedRowset))\n }\n next = await applyJoinFilters({\n db,\n baseTable,\n builder: next,\n joinMap,\n joinFilters,\n aliasTables,\n qualifyBase: (column) => qualify(column),\n applyAliasScope: async (target: any, alias: string) => applyAliasScopes(target as AnyBuilder, alias),\n applyFilterOp: (target, column, op, value) => applyJoinFilterOpFn(target as AnyBuilder, column, op, value),\n applyJoinFilterOp: async (target, filter, qualified, join) => {\n const applied = await applyJoinSearchFilterOp(target as AnyBuilder, filter, qualified, join)\n return { applied, builder: target }\n },\n columnExists: (tbl, column) => this.columnExists(tbl, column),\n })\n return next\n }\n\n // Selection (for data query)\n const selectFieldSet = new Set<string>((opts.fields && opts.fields.length) ? opts.fields.map(String) : Array.from(columns.keys()))\n if (requiresPlaintextSort) {\n for (const field of encryptedSortFields) selectFieldSet.add(field)\n }\n if (opts.includeCustomFields === true) {\n const entityIds = Array.from(new Set(indexSources.map((src) => String(src.entityId))))\n try {\n const resolvedKeys = await this.resolveAvailableCustomFieldKeys(entityIds, opts.tenantId ?? null)\n resolvedKeys.forEach((key) => selectFieldSet.add(`cf:${key}`))\n if (this.isDebugVerbosity()) this.debug('query:cf:resolved-keys', { entity, keys: resolvedKeys })\n } catch (err) {\n logger.warn('Failed to resolve custom field keys', { entity, err })\n }\n } else if (Array.isArray(opts.includeCustomFields)) {\n opts.includeCustomFields.map((key) => String(key)).forEach((key) => selectFieldSet.add(`cf:${key}`))\n }\n const selectFields = Array.from(selectFieldSet)\n\n const applySelection = (q: AnyBuilder, fieldsOverride?: string[]): AnyBuilder => {\n let next = q\n const fields = fieldsOverride ?? selectFields\n for (const field of fields) {\n const fieldName = String(field)\n if (fieldName.startsWith('cf:')) {\n const alias = this.sanitize(fieldName)\n const jsonExpr = this.buildCfJsonExprSql(fieldName, indexSources)\n const exprRaw = jsonExpr ?? sql`NULL::jsonb`\n next = next.select(exprRaw.as(alias))\n } else if (columns.has(fieldName)) {\n next = next.select(`${qualify(fieldName)} as ${fieldName}`)\n }\n }\n return next\n }\n\n const applySort = (q: AnyBuilder): AnyBuilder => {\n let next = q\n if (requiresPlaintextSort) return next\n for (const s of resolvedSorts) {\n const fieldName = String(s.field)\n if (fieldName.startsWith('cf:')) {\n const textExpr = this.buildCfTextExprSql(fieldName, indexSources)\n if (textExpr) {\n const direction = sql.raw(coerceSortDirection(s.dir))\n next = next.orderBy(sql`${textExpr} ${direction}`)\n }\n } else {\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) continue\n next = next.orderBy(qualify(baseField), s.dir ?? SortDir.Asc)\n }\n }\n return next\n }\n\n const page = opts.page?.page ?? 1\n const pageSize = opts.page?.pageSize ?? 20\n const sqlDebugEnabled = this.isSqlDebugEnabled()\n\n const countCap = resolveListCountCap()\n\n // Both count paths build the same rebuilt shape; for `canOptimizeCount`\n // queries `needsIndexRowset` is false, so the shape degenerates to\n // base-scope + filters exactly as the optimized path always had.\n // `wasOptimizable` carries NO control flow \u2014 it only labels the debug\n // timing so operators can keep telling the two shapes apart.\n // TODO(2026-08-12): remove `canOptimizeCount` once the shape convergence\n // has soaked (tracked in the #4552 spec as the Phase 2 follow-up).\n const runBoundedCount = async (wasOptimizable: boolean): Promise<{ total: number; warning?: ListCountCapWarning }> => {\n const countRoot = db.selectFrom(`${baseTable} as b` as any)\n const shape = await applyCountShape(countRoot)\n const countQuery = countCap !== null\n ? db\n .selectFrom(shape.select(sql<number>`1`.as('one')).limit(countCap + 1).as('om_count_probe') as any)\n .select(sql<string>`count(*)`.as('count'))\n : shape.select(sql<string>`count(*)`.as('count'))\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = countQuery.compile()\n this.debug('query:sql:count', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const countRow = await this.captureSqlTiming(\n 'query:sql:count', entity,\n () => countQuery.executeTakeFirst(),\n { optimized: wasOptimizable }, profiler,\n )\n const probed = this.parseCount(countRow)\n if (countCap !== null && probed > countCap) {\n return { total: countCap, warning: { entity, cap: countCap } }\n }\n return { total: probed }\n }\n\n const counted = await runBoundedCount(canOptimizeCount)\n const total: number = counted.total\n const listCountCapWarning: ListCountCapWarning | undefined = counted.warning\n\n const dekKeyCache = new Map<string | null, string | null>()\n\n const decryptRow = async (item: Record<string, unknown>): Promise<Record<string, unknown>> => {\n let next = item\n if (encSvc?.decryptEntityPayload) {\n const decrypt = encSvc.decryptEntityPayload.bind(encSvc) as (\n entityId: EntityId, payload: Record<string, unknown>, tenantId: string | null, organizationId: string | null,\n ) => Promise<Record<string, unknown>>\n try {\n const decrypted = await decrypt(\n entity, next,\n (next?.tenant_id ?? next?.tenantId ?? opts.tenantId ?? null) as string | null,\n (next?.organization_id ?? next?.organizationId ?? fallbackOrgId ?? null) as string | null,\n )\n next = { ...next, ...decrypted }\n } catch (err) {\n logger.error('Error decrypting entity payload', { err })\n }\n }\n if (encSvc) {\n try {\n next = await decryptIndexDocCustomFields(\n next,\n {\n tenantId: (next?.tenant_id ?? next?.tenantId ?? opts.tenantId ?? null) as string | null,\n organizationId: (next?.organization_id ?? next?.organizationId ?? null) as string | null,\n },\n encSvc as any, dekKeyCache,\n )\n } catch { /* keep next as-is */ }\n }\n return next\n }\n\n let items: Record<string, unknown>[]\n let encryptedSortRowCapWarning: EncryptedSortRowCapWarning | undefined\n\n if (requiresPlaintextSort) {\n // Phase 1: slim id+sort-columns candidate scan, bounded-concurrency decrypt,\n // in-memory sort over the full candidate set, then slice to the page's ids.\n const cap = resolveEncryptedSortMaxRows()\n const phase1Root = db.selectFrom(`${baseTable} as b` as any)\n let phase1 = await applyQueryShape(phase1Root)\n const scopeFieldNames = [\n hasTenantColumn ? 'tenant_id' : null,\n hasOrganizationColumn ? 'organization_id' : null,\n ].filter((field): field is string => field !== null)\n const sortFieldNames = Array.from(new Set(['id', ...scopeFieldNames, ...resolvedSorts.map((s) => String(s.field))]))\n phase1 = applySelection(phase1, sortFieldNames)\n if (cap !== null) {\n // Probe one row past the cap: truncation is detected from the candidate\n // scan itself, not by comparing against `total` \u2014 which may itself be\n // capped (`OM_LIST_COUNT_CAP`) and would then never exceed the sort cap.\n phase1 = phase1.limit(cap + 1).orderBy(qualify('id'), 'asc' as any)\n }\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = phase1.compile()\n this.debug('query:sql:data:phase1', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const candidateRowsRaw = await this.captureSqlTiming(\n 'query:sql:data:phase1', entity,\n () => phase1.execute(),\n { phase: 1 }, profiler,\n ) as Record<string, unknown>[]\n const sortTruncated = cap !== null && candidateRowsRaw.length > cap\n const candidateRows = sortTruncated && cap !== null ? candidateRowsRaw.slice(0, cap) : candidateRowsRaw\n const decryptedCandidates = await mapWithConcurrency(candidateRows, DECRYPT_CONCURRENCY, decryptRow)\n const orderedCandidates = sortRowsInMemory(decryptedCandidates, resolvedSorts)\n const pageIds = orderedCandidates\n .slice((page - 1) * pageSize, page * pageSize)\n .map((row) => row.id)\n\n if (sortTruncated && cap !== null) {\n encryptedSortRowCapWarning = {\n entity,\n sortFields: resolvedSorts.map((s) => String(s.field)),\n maxRows: cap,\n totalMatched: total,\n }\n }\n\n // Phase 2: fetch + decrypt full rows for just the page's ids, then reassemble\n // in phase-1's order (SQL `WHERE id IN (...)` order is unspecified \u2014 never\n // trust it for ordering).\n if (pageIds.length === 0) {\n items = []\n } else {\n const phase2Root = db.selectFrom(`${baseTable} as b` as any)\n let phase2 = await applyQueryShape(phase2Root)\n phase2 = applySelection(phase2)\n phase2 = phase2.where(qualify('id'), 'in', pageIds)\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = phase2.compile()\n this.debug('query:sql:data:phase2', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const pageRowsRaw = await this.captureSqlTiming(\n 'query:sql:data:phase2', entity,\n () => phase2.execute(),\n { phase: 2 }, profiler,\n ) as Record<string, unknown>[]\n const decryptedPageRows = await mapWithConcurrency(pageRowsRaw, DECRYPT_CONCURRENCY, decryptRow)\n const byId = new Map(decryptedPageRows.map((row) => [String(row.id), row]))\n items = pageIds\n .map((id) => byId.get(String(id)))\n .filter((row): row is Record<string, unknown> => row != null)\n }\n } else {\n const dataRoot = db.selectFrom(`${baseTable} as b` as any)\n let dataBuilder = await applyQueryShape(dataRoot)\n dataBuilder = applySelection(dataBuilder)\n dataBuilder = applySort(dataBuilder)\n dataBuilder = dataBuilder.limit(pageSize).offset((page - 1) * pageSize)\n\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = dataBuilder.compile()\n this.debug('query:sql:data', { entity, sql: compiled.sql, bindings: compiled.parameters, page, pageSize })\n }\n const itemsRaw = await this.captureSqlTiming(\n 'query:sql:data', entity,\n () => dataBuilder.execute(),\n { page, pageSize }, profiler,\n ) as Record<string, unknown>[]\n items = await mapWithConcurrency(itemsRaw, DECRYPT_CONCURRENCY, decryptRow)\n }\n if (debugEnabled) this.debug('query:complete', { entity, total, items: items.length })\n\n const typedItems = items as unknown as T[]\n let result: QueryResult<T> = { items: typedItems, page, pageSize, total }\n if (partialIndexWarning || encryptedSortRowCapWarning || listCountCapWarning) {\n const meta: QueryResultMeta = {}\n if (partialIndexWarning) meta.partialIndexWarning = partialIndexWarning\n if (encryptedSortRowCapWarning) meta.encryptedSortRowCapWarning = encryptedSortRowCapWarning\n if (listCountCapWarning) meta.listCountCapWarning = listCountCapWarning\n result.meta = meta\n }\n\n result = await applyAfterExtensions(result)\n finishProfile({\n result: 'ok', total, page, pageSize,\n itemCount: Array.isArray(items) ? items.length : undefined,\n partialIndexWarning: partialIndexWarning ? true : false,\n })\n return result\n } catch (err) {\n finishProfile({ result: 'error', error: err instanceof Error ? err.message : String(err) })\n throw err\n }\n }\n\n private prepareCustomFieldSources(\n sources: QueryCustomFieldSource[],\n ): PreparedCustomFieldSource[] {\n const prepared: PreparedCustomFieldSource[] = []\n sources.forEach((source, index) => {\n if (!source) return\n const joinTable = source.table ?? resolveEntityTableName(this.em, source.entityId)\n const alias = source.alias ?? `cfs_${index}`\n if (!source.join) {\n throw new Error(`QueryEngine: customFieldSources entry for ${String(source.entityId)} requires a join configuration`)\n }\n prepared.push({\n alias,\n indexAlias: `ei_${alias}`,\n entityId: source.entityId,\n recordIdColumn: source.recordIdColumn ?? 'id',\n organizationField: source.organizationField,\n tenantField: source.tenantField,\n table: joinTable,\n })\n })\n return prepared\n }\n\n private async isCustomEntity(entity: string): Promise<boolean> {\n const cached = this.customEntityCache.get(entity)\n if (cached !== undefined) return cached\n let result = false\n try {\n if (isOrmBackedSystemEntityId(this.em, entity)) {\n // An id backed by a registered ORM table is never doc-storage-backed. Classify it\n // as its base table BEFORE probing `custom_entities`, so neither a stray\n // `custom_entities_storage` row nor an active `custom_entities` row (e.g. a\n // presentation-metadata overlay for a system entity) can hijack every list/detail\n // read for the whole entity type away from its base table (#2939). This mirrors the\n // ORM-backed-first ordering already used by the records API (`classifyRecordsEntity`)\n // and the doc-storage write guard (`assertCustomEntityStorageEntityId`); without it\n // the read classifier alone trusted an active registration row over ORM-table\n // resolution. Surfaces that intentionally read doc records for a dual-declared id\n // pass `forceCustomEntityStorage` in QueryOptions instead.\n result = false\n } else {\n const db = this.getDb() as any\n const row = await db\n .selectFrom('custom_entities')\n .select('id')\n .where('entity_id', '=', entity)\n .where('is_active', '=', true)\n .executeTakeFirst()\n if (row) {\n result = true\n } else if (resolveRegisteredEntityTableName(this.em, entity) !== null) {\n // A non-registry id whose entity segment collides with an ORM class name (e.g.\n // `user:todo` vs the example module's `Todo`) resolves to a table but is NOT an\n // ORM-backed system entity, so it is not short-circuited above. Stray\n // `custom_entities_storage` rows for such an id must not hijack reads either.\n result = false\n } else {\n // Read/write symmetry. Records written through the entities data engine\n // (`de.createCustomEntityRecord`) always land in `custom_entities_storage`,\n // even for module-declared custom entities whose id is also a frozen system\n // id \u2014 those are NEVER registered in `custom_entities` (install treats a\n // system id as non-registrable). Without this fallback the query routes to\n // the empty ORM/index path and those records are write-only (created with\n // 200 but unreadable on the edit form).\n result = await this.hasCustomEntityStorageRows(entity)\n }\n }\n } catch {\n result = false\n }\n this.customEntityCache.set(entity, result)\n return result\n }\n\n private async hasCustomEntityStorageRows(entity: string): Promise<boolean> {\n try {\n const db = this.getDb() as any\n const row = await db\n .selectFrom('custom_entities_storage')\n .select(sql<number>`1`.as('one'))\n .where('entity_type', '=', entity)\n .limit(1)\n .executeTakeFirst()\n return !!row\n } catch {\n return false\n }\n }\n\n /**\n * Adds a WHERE EXISTS / OR WHERE EXISTS subquery that matches\n * `search_tokens` for the supplied (entity, field) against the\n * provided record id column.\n *\n * Returns true when the sub-query was applied (i.e. tokens were\n * non-empty). Caller is responsible for the calling context\n * (direct where vs. inside `eb.or([...])`).\n */\n private applySearchTokens(\n q: AnyBuilder,\n opts: {\n entity: string\n field: string\n hashes: string[]\n recordIdColumn: string\n tenantId?: string | null\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n combineWith?: 'and' | 'or'\n mintAlias: () => string\n }\n ): boolean {\n if (!opts.hashes.length) {\n this.logSearchDebug('search:skip-no-hashes', {\n entity: opts.entity, field: opts.field,\n tenantId: opts.tenantId ?? null, organizationScope: opts.organizationScope,\n })\n return false\n }\n const alias = opts.mintAlias()\n this.logSearchDebug('search:apply-search-tokens', {\n entity: opts.entity, field: opts.field, alias,\n tokenCount: opts.hashes.length,\n tenantId: opts.tenantId ?? null,\n organizationScope: opts.organizationScope,\n combineWith: opts.combineWith ?? 'and',\n })\n\n const engine = this\n const buildSub = (eb: any) => {\n let sub = eb\n .selectFrom(`search_tokens as ${alias}`)\n .select(sql<number>`1`.as('one'))\n .where(`${alias}.entity_type`, '=', opts.entity)\n .where(`${alias}.field`, '=', opts.field)\n .where(sql<boolean>`${sql.ref(`${alias}.entity_id`)} = ${sql.ref(opts.recordIdColumn)}::text`)\n .where(`${alias}.token_hash`, 'in', opts.hashes)\n .groupBy([`${alias}.entity_id`, `${alias}.field`])\n .having(sql<boolean>`count(distinct ${sql.ref(`${alias}.token_hash`)}) >= ${opts.hashes.length}`)\n if (opts.tenantId !== undefined) {\n sub = sub.where(sql<boolean>`${sql.ref(`${alias}.tenant_id`)} is not distinct from ${opts.tenantId ?? null}`)\n }\n if (opts.organizationScope) {\n sub = engine.applyOrganizationScope(sub, `${alias}.organization_id`, opts.organizationScope)\n }\n return sub\n }\n\n if (opts.combineWith === 'or') {\n // When called inside an .or([...]) array the caller supplied `eb`.\n // `q` is the ExpressionBuilder callable (eb) itself in that case.\n // We return the expression node rather than mutating q.\n ;(q as any).__pendingOrExists = buildSub(q)\n return true\n }\n\n // Default: append WHERE EXISTS (...) to the outer builder.\n ;(q as any).__applied = true\n const built = buildSub(q)\n // If q is a Kysely builder (has .where), use eb => eb.exists(sub)\n if (typeof q.where === 'function') {\n ;(q as any) = q.where((eb: any) => eb.exists(built))\n }\n return true\n }\n\n /** SQL fragment for `cf:<key>` (or legacy bare key) as JSON across a single alias. */\n private jsonbSqlAlias(alias: string, key: string): RawBuilder<unknown> {\n if (key.startsWith('cf:')) {\n const bare = key.slice(3)\n return sql`coalesce(${sql.ref(alias + '.doc')} -> ${key}, ${sql.ref(alias + '.doc')} -> ${bare})`\n }\n return sql`${sql.ref(alias + '.doc')} -> ${key}`\n }\n\n /** SQL fragment for `cf:<key>` (or legacy bare key) as text across a single alias. */\n private cfTextExprAlias(alias: string, key: string): RawBuilder<string | null> {\n if (key.startsWith('cf:')) {\n const bare = key.slice(3)\n return sql<string | null>`coalesce((${sql.ref(alias + '.doc')} ->> ${key}), (${sql.ref(alias + '.doc')} ->> ${bare}))`\n }\n return sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n }\n\n /** Build JSON/text SQL expressions across multiple index alias sources (coalesce over them). */\n private buildCfJsonExprSql(key: string, sources: IndexDocSource[]): RawBuilder<unknown> | null {\n if (!sources.length) return null\n const parts = sources.map((src) => this.jsonbSqlAlias(src.alias, key))\n if (parts.length === 1) return parts[0]\n return sql`coalesce(${sql.join(parts, sql`, `)})`\n }\n\n private buildCfTextExprSql(key: string, sources: IndexDocSource[]): RawBuilder<string | null> | null {\n if (!sources.length) return null\n const parts = sources.map((src) => this.cfTextExprAlias(src.alias, key))\n if (parts.length === 1) return parts[0]\n return sql<string | null>`coalesce(${sql.join(parts, sql`, `)})`\n }\n\n /**\n * Build a custom-field predicate as a standalone expression.\n *\n * Returning an expression rather than mutating a builder is what lets OR-grouped\n * cf leaves be combined with the base-column ones inside a single `WHERE`\n * (#5039). `null` means \"no predicate\" \u2014 an empty search-token set or an\n * unsupported operator \u2014 and callers must treat that as the leaf being absent.\n */\n private buildCfFilterExpression(\n eb: any,\n key: string,\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime\n ): any | null {\n if (!sources.length) return null\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (!hashes.length) {\n this.logSearchDebug('search:cf-skip-empty-hashes', {\n entity: sources.map((src) => src.entityId), field: key, value,\n })\n return null\n }\n const expression = this.buildMultiSourceSearchExists(eb, sources, key, hashes, search)\n this.logSearchDebug('search:cf-filter-across', {\n entity: sources.map((src) => src.entityId),\n field: key, tokens: tokens.tokens, hashes, applied: expression !== null,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return expression\n }\n\n const textExpr = this.buildCfTextExprSql(key, sources)\n const jsonExpr = this.buildCfJsonExprSql(key, sources)\n if (!textExpr || !jsonExpr) return null\n\n const arrContains = (val: unknown) => sql<boolean>`${jsonExpr} @> ${JSON.stringify([val])}::jsonb`\n\n switch (op) {\n case 'eq':\n // An unset custom field has no array element to contain, so the\n // arrContains branch cannot match it \u2014 compare the text value only.\n return value === null\n ? sql<boolean>`${textExpr} is null`\n : eb.or([\n sql<boolean>`${textExpr} = ${value}`,\n arrContains(value),\n ])\n case 'ne':\n return value === null\n ? sql<boolean>`${textExpr} is not null`\n : sql<boolean>`${textExpr} <> ${value}`\n case 'in': {\n const values = this.toArray(value)\n return eb.or(\n values.flatMap((val) => [\n sql<boolean>`${textExpr} = ${val}`,\n arrContains(val),\n ])\n )\n }\n case 'nin': {\n const values = this.toArray(value)\n return sql<boolean>`${textExpr} not in (${sql.join(values.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'like':\n return sql<boolean>`${textExpr} like ${value}`\n case 'ilike':\n return sql<boolean>`${textExpr} ilike ${value}`\n case 'exists':\n return value\n ? sql<boolean>`${textExpr} is not null`\n : sql<boolean>`${textExpr} is null`\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return sql<boolean>`${textExpr} ${operator} ${value}`\n }\n default:\n return null\n }\n }\n\n /**\n * Whether `buildCfFilterExpression` will produce a predicate for this leaf.\n *\n * Decidable without an ExpressionBuilder, which lets callers skip the `.where()`\n * entirely (rather than emitting a tautology) and lets the OR-group builder drop\n * leaves before it has to decide whether a disjunct survives.\n */\n private cfFilterHasPredicate(\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime,\n ): boolean {\n if (!sources.length) return false\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n return tokenizeText(String(value), search.config).hashes.length > 0\n }\n return CF_FILTER_SUPPORTED_OPS.has(op)\n }\n\n private applyCfFilterAcrossSources(\n builder: AnyBuilder,\n key: string,\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime\n ): AnyBuilder {\n if (!this.cfFilterHasPredicate(op, value, sources, search)) {\n // Preserve the pre-existing behaviour of dropping a leaf we cannot compile.\n if (sources.length && (op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n this.logSearchDebug('search:cf-skip-empty-hashes', {\n entity: sources.map((src) => src.entityId), field: key, value,\n })\n }\n return builder\n }\n return builder.where((eb: any) => this.buildCfFilterExpression(eb, key, op, value, sources, search))\n }\n\n /** Build a search-token EXISTS predicate across multiple sources (OR-joined). */\n private buildMultiSourceSearchExists(\n eb: any,\n sources: IndexDocSource[],\n key: string,\n hashes: string[],\n search: SearchRuntime,\n ): any | null {\n if (!sources.length || !hashes.length) return null\n return eb.or(\n sources.map((source) =>\n eb.exists(this.buildSearchTokensSub(eb, {\n entity: String(source.entityId),\n field: key, hashes,\n recordIdColumn: `${source.alias}.entity_id`,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n }))\n )\n )\n }\n\n /** Construct a search-token EXISTS subquery using the given ExpressionBuilder. */\n private buildSearchTokensSub(\n eb: any,\n opts: {\n entity: string\n field: string\n hashes: string[]\n recordIdColumn: string\n tenantId?: string | null\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n mintAlias: () => string\n }\n ): any {\n const alias = opts.mintAlias()\n let sub = eb\n .selectFrom(`search_tokens as ${alias}`)\n .select(sql<number>`1`.as('one'))\n .where(`${alias}.entity_type`, '=', opts.entity)\n .where(`${alias}.field`, '=', opts.field)\n .where(sql<boolean>`${sql.ref(`${alias}.entity_id`)} = ${sql.ref(opts.recordIdColumn)}::text`)\n .where(`${alias}.token_hash`, 'in', opts.hashes)\n .groupBy([`${alias}.entity_id`, `${alias}.field`])\n .having(sql<boolean>`count(distinct ${sql.ref(`${alias}.token_hash`)}) >= ${opts.hashes.length}`)\n if (opts.tenantId !== undefined) {\n sub = sub.where(sql<boolean>`${sql.ref(`${alias}.tenant_id`)} is not distinct from ${opts.tenantId ?? null}`)\n }\n if (opts.organizationScope) {\n sub = this.applyOrganizationScope(sub, `${alias}.organization_id`, opts.organizationScope)\n }\n return sub\n }\n\n private applyCfFilterFromAlias(\n q: AnyBuilder,\n alias: string,\n entityType: string,\n key: string,\n op: FilterOp,\n value: unknown,\n search?: SearchRuntime\n ): AnyBuilder {\n const textExpr = this.cfTextExprAlias(alias, key)\n const arrExpr = sql<unknown>`(${sql.ref(alias + '.doc')} -> ${key})`\n const arrContains = (val: unknown) => sql<boolean>`${arrExpr} @> ${JSON.stringify([val])}::jsonb`\n\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const applied = q.where((eb: any) => eb.exists(this.buildSearchTokensSub(eb, {\n entity: entityType, field: key, hashes,\n recordIdColumn: `${alias}.entity_id`,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n this.logSearchDebug('search:cf-filter', {\n entity: entityType, field: key, tokens: tokens.tokens, hashes, applied: true,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return applied\n } else {\n this.logSearchDebug('search:cf-skip-empty-hashes', { entity: entityType, field: key, value })\n }\n return q\n }\n switch (op) {\n case 'eq':\n // An unset custom field has no array element to contain, so the\n // arrContains branch cannot match it \u2014 compare the text value only.\n return value === null\n ? q.where(sql<boolean>`${textExpr} is null`)\n : q.where((eb: any) => eb.or([\n sql<boolean>`${textExpr} = ${value}`,\n arrContains(value),\n ]))\n case 'ne':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} <> ${value}`)\n case 'in': {\n const vals = this.toArray(value)\n return q.where((eb: any) => eb.or(\n vals.flatMap((val) => [\n sql<boolean>`${textExpr} = ${val}`,\n arrContains(val),\n ])\n ))\n }\n case 'nin': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'like':\n return q.where(sql<boolean>`${textExpr} like ${value}`)\n case 'ilike':\n return q.where(sql<boolean>`${textExpr} ilike ${value}`)\n case 'exists':\n return value\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} is null`)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return q.where(sql<boolean>`${textExpr} ${operator} ${value}`)\n }\n default:\n return q\n }\n }\n\n private applyIndexDocFilterFromAlias(\n q: AnyBuilder,\n alias: string,\n entityType: string,\n key: string,\n op: FilterOp,\n value: unknown,\n recordIdColumn: string,\n search?: SearchRuntime,\n ): AnyBuilder {\n const textExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const applied = q.where((eb: any) => eb.exists(this.buildSearchTokensSub(eb, {\n entity: entityType, field: key, hashes, recordIdColumn,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n this.logSearchDebug('search:index-doc-filter', {\n entity: entityType, field: key, tokens: tokens.tokens, hashes, applied: true,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return applied\n } else {\n this.logSearchDebug('search:index-doc-skip-empty-hashes', { entity: entityType, field: key, value })\n }\n return q\n }\n switch (op) {\n case 'eq':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is null`)\n : q.where(sql<boolean>`${textExpr} = ${value}`)\n case 'ne':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} <> ${value}`)\n case 'in': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'nin': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'like':\n return q.where(sql<boolean>`${textExpr} like ${value}`)\n case 'ilike':\n return q.where(sql<boolean>`${textExpr} ilike ${value}`)\n case 'exists':\n return value\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} is null`)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return q.where(sql<boolean>`${textExpr} ${operator} ${value}`)\n }\n default:\n return q\n }\n }\n\n /**\n * Build a single OR-group base filter expression as a Kysely predicate\n * (no side effects on the outer builder).\n */\n private buildBaseFilterExpression(\n eb: any,\n filter: BaseFilter,\n resolveBaseColumn: (field: string) => string | null,\n qualify: (col: string) => string,\n entity: EntityId,\n searchRuntime: SearchRuntime,\n ): any {\n const fieldName = String(filter.field)\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) {\n // Doc-based filter via `ei` alias \u2014 returned as EXISTS where possible\n return this.buildIndexDocFilterExpression(eb, 'ei', entity, fieldName, filter.op, filter.value, 'b.id', searchRuntime)\n }\n // For like/ilike with active search-tokens, route through hashed-token EXISTS subquery\n // so encrypted-at-rest columns can still be searched. Plaintext base columns keep exact\n // SQL ILIKE -- see SearchRuntime.encryptedFields.\n if (\n (filter.op === 'like' || filter.op === 'ilike') &&\n searchRuntime?.enabled &&\n typeof filter.value === 'string' &&\n (searchRuntime.encryptedFields == null || isEncryptedLikeField(searchRuntime.encryptedFields, fieldName))\n ) {\n const tokens = tokenizeText(String(filter.value), searchRuntime.config)\n if (tokens.hashes.length) {\n const sources: SearchTokenSource[] = (searchRuntime.searchSources && searchRuntime.searchSources.length\n ? searchRuntime.searchSources\n : [{ entity: String(entity), recordIdColumn: 'b.id' }]\n ).filter((src) => src.recordIdColumn && src.entity)\n if (sources.length) {\n return eb.or(\n sources.map((src) =>\n eb.exists(this.buildSearchTokensSub(eb, {\n entity: src.entity,\n field: fieldName,\n hashes: tokens.hashes,\n recordIdColumn: src.recordIdColumn,\n tenantId: searchRuntime.tenantId ?? null,\n organizationScope: searchRuntime.organizationScope ?? null,\n mintAlias: searchRuntime.mintAlias,\n })),\n ),\n )\n }\n }\n // Tokenizer produced no hashes (e.g. value too short) or no source is usable. For a\n // column KNOWN to be encrypted, `false` is the honest answer for an OR leaf -- `true`\n // would widen the whole disjunction to match everything, on exactly the columns ILIKE\n // cannot serve. Every other case (gate off, custom-entity runtime, resolution failure)\n // keeps the legacy predicate-skipping `true`.\n return searchRuntime?.encryptedFields != null && isEncryptedLikeField(searchRuntime.encryptedFields, fieldName)\n ? sql<boolean>`false`\n : sql<boolean>`true`\n }\n return this.buildColumnFilterExpression(eb, qualify(baseField), filter.op, filter.value)\n }\n\n private buildColumnFilterExpression(\n eb: any,\n column: string,\n op: FilterOp,\n value: unknown,\n ): any {\n switch (op) {\n case 'eq': return value === null ? eb(column, 'is', null) : eb(column, '=', value)\n case 'ne': return value === null ? eb(column, 'is not', null) : eb(column, '!=', value)\n case 'gt': return eb(column, '>', value)\n case 'gte': return eb(column, '>=', value)\n case 'lt': return eb(column, '<', value)\n case 'lte': return eb(column, '<=', value)\n case 'in': return eb(column, 'in', this.toArray(value))\n case 'nin': return eb(column, 'not in', this.toArray(value))\n case 'like': return eb(column, 'like', value)\n case 'ilike': return eb(column, 'ilike', value)\n case 'exists': return eb(column, value ? 'is not' : 'is', null)\n default: return sql<boolean>`true`\n }\n }\n\n private buildIndexDocFilterExpression(\n eb: any,\n alias: string,\n _entity: EntityId,\n key: string,\n op: FilterOp,\n value: unknown,\n _recordIdColumn: string,\n _search?: SearchRuntime,\n ): any {\n const textExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n switch (op) {\n case 'eq': return value === null ? sql<boolean>`${textExpr} is null` : sql<boolean>`${textExpr} = ${value}`\n case 'ne': return value === null ? sql<boolean>`${textExpr} is not null` : sql<boolean>`${textExpr} <> ${value}`\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return sql<boolean>`${textExpr} ${operator} ${value}`\n }\n case 'like': return sql<boolean>`${textExpr} like ${value}`\n case 'ilike': return sql<boolean>`${textExpr} ilike ${value}`\n case 'in': {\n const vals = this.toArray(value)\n return sql<boolean>`${textExpr} in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'nin': {\n const vals = this.toArray(value)\n return sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'exists':\n return value ? sql<boolean>`${textExpr} is not null` : sql<boolean>`${textExpr} is null`\n default:\n return sql<boolean>`true`\n }\n }\n\n private async queryCustomEntity<T = unknown>(entity: string, opts: QueryOptions = {}): Promise<QueryResult<T>> {\n const db = this.getDb() as any\n const alias = 'ce'\n\n const orgScope = this.resolveOrganizationScope(opts)\n if (!opts.tenantId) throw new Error('QueryEngine: tenantId is required')\n\n const normalizedFilters = normalizeFilters(opts.filters)\n const searchConfig = resolveSearchConfig()\n const searchEnabled = await this.searchAvailability().staticEnabled()\n // Same gate as `query()` (#4723): without a like/ilike filter the probe's answer is never read.\n const hasSearchTokens = searchEnabled && hasSearchFilter(normalizedFilters)\n ? await this.searchAvailability().hasTokens(entity, opts.tenantId ?? null, orgScope)\n : false\n // `encryptedFields` is deliberately NOT resolved here: custom-entity rows live in the\n // `entity_indexes` doc store, whose fields the base-column encryption map does not describe,\n // so the ILIKE gate stays inert on this path and like/ilike keeps its previous semantics.\n const searchRuntime: SearchRuntime = {\n enabled: searchEnabled && hasSearchTokens,\n config: searchConfig,\n organizationScope: orgScope,\n tenantId: opts.tenantId ?? null,\n mintAlias: createSearchAliasMinter(),\n }\n\n const applyScope = (q: AnyBuilder): AnyBuilder => {\n let next = q\n .where(`${alias}.entity_type`, '=', entity)\n .where(`${alias}.tenant_id`, '=', opts.tenantId)\n if (orgScope) {\n next = this.applyOrganizationScope(next, `${alias}.organization_id`, orgScope)\n }\n if (!opts.withDeleted) next = next.where(`${alias}.deleted_at`, 'is', null)\n for (const filter of normalizedFilters) {\n if (filter.field.startsWith('cf:')) {\n next = this.applyCfFilterFromAlias(next, alias, entity, filter.field, filter.op, filter.value, searchRuntime)\n continue\n }\n const column = this.resolveCustomEntityColumn(alias, String(filter.field))\n if (column) {\n next = this.applyColumnFilter(next, column, filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: `${alias}.entity_id`,\n })\n continue\n }\n // Unknown field \u2192 filter on doc JSON text\n const docExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${String(filter.field)})`\n next = this.applyColumnFilter(next, docExpr, filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: `${alias}.entity_id`,\n })\n }\n return next\n }\n\n // Determine CFs and l10n keys to include\n const cfKeys = new Set<string>()\n for (const f of (opts.fields || [])) {\n if (typeof f === 'string' && f.startsWith('cf:')) cfKeys.add(f.slice(3))\n else if (typeof f === 'string' && f.startsWith('l10n:')) cfKeys.add(f)\n }\n for (const filter of normalizedFilters) {\n if (typeof filter.field === 'string' && filter.field.startsWith('cf:')) cfKeys.add(filter.field.slice(3))\n else if (typeof filter.field === 'string' && filter.field.startsWith('l10n:')) cfKeys.add(filter.field)\n }\n if (opts.includeCustomFields === true) {\n try {\n const rows = await db\n .selectFrom('custom_field_defs')\n .select('key')\n .where('entity_id', '=', entity)\n .where('is_active', '=', true)\n .where('tenant_id', '=', opts.tenantId)\n .execute() as Array<{ key: unknown }>\n for (const row of rows) {\n const key = row.key\n if (typeof key === 'string') cfKeys.add(key)\n else if (key != null) cfKeys.add(String(key))\n }\n } catch {\n // ignore\n }\n } else if (Array.isArray(opts.includeCustomFields)) {\n for (const k of opts.includeCustomFields) cfKeys.add(k)\n }\n\n const applySelection = (q: AnyBuilder): AnyBuilder => {\n let next = q\n const requested = (opts.fields && opts.fields.length) ? opts.fields : ['id']\n for (const field of requested) {\n const f = String(field)\n if (f.startsWith('cf:')) {\n const aliasName = this.sanitize(f)\n next = next.select(this.jsonbSqlAlias(alias, f).as(aliasName))\n } else if (f === 'id') {\n next = next.select(`${alias}.entity_id as id`)\n } else if (f === 'created_at' || f === 'updated_at' || f === 'deleted_at') {\n next = next.select(`${alias}.${f} as ${f}`)\n } else {\n const expr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${f})`\n next = next.select(expr.as(f))\n }\n }\n // Ensure CF fields for sort / includeCustomFields are selected\n for (const key of cfKeys) {\n const aliasName = this.sanitize(`cf:${key}`)\n next = next.select(this.jsonbSqlAlias(alias, `cf:${key}`).as(aliasName))\n }\n return next\n }\n\n const applySort = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const s of opts.sort || []) {\n if (s.field.startsWith('cf:')) {\n const key = s.field.slice(3)\n const aliasName = this.sanitize(`cf:${key}`)\n next = next.orderBy(aliasName, s.dir ?? SortDir.Asc)\n } else if (s.field === 'id') {\n next = next.orderBy(`${alias}.entity_id`, s.dir ?? SortDir.Asc)\n } else if (s.field === 'created_at' || s.field === 'updated_at' || s.field === 'deleted_at') {\n next = next.orderBy(`${alias}.${s.field}`, s.dir ?? SortDir.Asc)\n } else {\n const direction = sql.raw(coerceSortDirection(s.dir))\n next = next.orderBy(sql`(${sql.ref(alias + '.doc')} ->> ${s.field}) ${direction}`)\n }\n }\n return next\n }\n\n const page = opts.page?.page ?? 1\n const pageSize = opts.page?.pageSize ?? 20\n\n // Single-table count: `applyScope` adds only WHERE predicates (cf filters\n // included \u2014 no join), and doc storage holds one row per record within a\n // scope, so `count(*)` needs no DISTINCT and \u2014 when the cap is active \u2014 a\n // LIMIT on the row-producing inner query bounds the scan (#4552 Phase 2).\n const countCap = resolveListCountCap()\n const root = db.selectFrom(`custom_entities_storage as ${alias}`)\n const countShape = applyScope(root)\n const countQuery = countCap !== null\n ? db\n .selectFrom(countShape.select(sql<number>`1`.as('one')).limit(countCap + 1).as('om_count_probe') as any)\n .select(sql<string>`count(*)`.as('count'))\n : countShape.select(sql<string>`count(*)`.as('count'))\n const countRow = await countQuery.executeTakeFirst()\n const probed = this.parseCount(countRow)\n let total = probed\n let listCountCapWarning: ListCountCapWarning | undefined\n if (countCap !== null && probed > countCap) {\n total = countCap\n listCountCapWarning = { entity: entity as EntityId, cap: countCap }\n }\n\n let dataQuery = applyScope(db.selectFrom(`custom_entities_storage as ${alias}`))\n dataQuery = applySelection(dataQuery)\n dataQuery = applySort(dataQuery)\n dataQuery = dataQuery.limit(pageSize).offset((page - 1) * pageSize)\n const items = await dataQuery.execute()\n const result: QueryResult<T> = { items, page, pageSize, total }\n if (listCountCapWarning) result.meta = { listCountCapWarning }\n return result\n }\n\n private async tableExists(table: string): Promise<boolean> {\n const db = this.getDb() as any\n const exists = await db\n .selectFrom('information_schema.tables')\n .select(sql<number>`1`.as('one'))\n .where('table_name', '=', table)\n .executeTakeFirst()\n return !!exists\n }\n\n private async resolveAvailableCustomFieldKeys(entityIds: string[], tenantId: string | null): Promise<string[]> {\n if (!entityIds.length) return []\n const cacheKey = this.customFieldKeysCacheKey(entityIds, tenantId)\n const now = Date.now()\n const cached = this.customFieldKeysCache.get(cacheKey)\n if (cached && cached.expiresAt > now) return cached.value.slice()\n\n const db = this.getDb() as any\n const rows = await db\n .selectFrom('custom_field_defs')\n .select('key')\n .where('entity_id', 'in', entityIds)\n .where('is_active', '=', true)\n .where((eb: any) => eb.or([\n eb('tenant_id', '=', tenantId),\n eb('tenant_id', 'is', null),\n ]))\n .execute() as Array<{ key: unknown }>\n const keys = new Set<string>()\n for (const row of rows) {\n const key = row.key\n if (typeof key === 'string' && key.trim().length) keys.add(key.trim())\n else if (key != null) keys.add(String(key))\n }\n const result = Array.from(keys)\n if (this.customFieldKeysTtlMs > 0) {\n this.customFieldKeysCache.set(cacheKey, { expiresAt: now + this.customFieldKeysTtlMs, value: result })\n }\n return result.slice()\n }\n\n private async entityHasActiveCustomFields(entityId: string, tenantId: string | null): Promise<boolean> {\n try {\n const keys = await this.resolveAvailableCustomFieldKeys([entityId], tenantId)\n return keys.length > 0\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('query:cf:check-error', {\n entity: entityId, tenantId: tenantId ?? null,\n error: err instanceof Error ? err.message : err,\n })\n }\n return true\n }\n }\n\n private customFieldKeysCacheKey(entityIds: string[], tenantId: string | null): string {\n const sorted = entityIds.slice().sort((a, b) => a.localeCompare(b)).join(',')\n return `${tenantId ?? '__none__'}|${sorted}`\n }\n\n private resolveVectorService(): VectorIndexService | null {\n if (!this.vectorServiceResolver) return null\n try {\n return this.vectorServiceResolver() ?? null\n } catch {\n return null\n }\n }\n\n private resolveEntityLabel(entity: string): string {\n return entity\n }\n\n private async indexAnyRows(entity: string): Promise<boolean> {\n const db = this.getDb() as any\n const coverage = await db\n .selectFrom('entity_index_coverage')\n .select(sql<number>`1`.as('one'))\n .where('entity_type', '=', entity)\n .where('indexed_count', '>', 0)\n .executeTakeFirst()\n if (coverage) return true\n const exists = await db\n .selectFrom('entity_indexes')\n .select('entity_id')\n .where('entity_type', '=', entity)\n .executeTakeFirst()\n return !!exists\n }\n\n private async getStoredCoverageSnapshot(\n entity: string,\n tenantId: string | null,\n organizationId: string | null,\n withDeleted: boolean\n ): Promise<{ baseCount: number; indexedCount: number } | null> {\n try {\n const db = this.getDb()\n const scope = {\n entityType: entity, tenantId, organizationId, withDeleted,\n }\n const row = await readCoverageSnapshot(db as any, scope)\n if (row && this.isCoverageSnapshotFresh(row)) {\n return { baseCount: row.baseCount, indexedCount: row.indexedCount }\n }\n\n if (this.isCoverageOptimizationEnabled()) {\n this.scheduleCoverageRefresh(entity, tenantId, organizationId, withDeleted)\n if (!row) return null\n return { baseCount: row.baseCount, indexedCount: row.indexedCount }\n }\n\n await refreshCoverageSnapshot(this.em, scope)\n const refreshed = await readCoverageSnapshot(db as any, scope)\n if (!refreshed) return null\n return { baseCount: refreshed.baseCount, indexedCount: refreshed.indexedCount }\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('coverage:snapshot:read-error', {\n entity, tenantId, organizationId, withDeleted,\n error: err instanceof Error ? err.message : err,\n })\n }\n return null\n }\n }\n\n private isCoverageSnapshotFresh(\n row: Awaited<ReturnType<typeof readCoverageSnapshot>>\n ): boolean {\n if (this.coverageStatsTtlMs <= 0) return false\n if (!row) return false\n const refreshedAt = row.refreshed_at instanceof Date\n ? row.refreshed_at\n : row.refreshed_at\n ? new Date(row.refreshed_at)\n : null\n const refreshedAtMs = refreshedAt?.getTime()\n if (!refreshedAtMs || !Number.isFinite(refreshedAtMs)) return false\n return Date.now() - refreshedAtMs <= this.coverageStatsTtlMs\n }\n\n private scheduleAutoReindex(\n entity: string,\n opts: QueryOptions,\n stats?: { baseCount: number; indexedCount: number },\n organizationIdOverride?: string | null\n ) {\n if (!this.isAutoReindexEnabled()) return\n const bus = this.resolveEventBus()\n if (!bus) return\n const payload = {\n entityType: entity,\n tenantId: opts.tenantId ?? null,\n organizationId: organizationIdOverride ?? opts.organizationId ?? null,\n force: false,\n }\n const debounceMs = this.getAutoReindexDebounceMs()\n if (debounceMs > 0) {\n const key = [payload.entityType, payload.tenantId ?? '__tenant__', payload.organizationId ?? '__org__'].join('|')\n if (!markAutoReindexScheduled(key, debounceMs, Date.now())) return\n }\n const context = stats\n ? { entity, tenantId: payload.tenantId, organizationId: payload.organizationId, baseCount: stats.baseCount, indexedCount: stats.indexedCount }\n : { entity, tenantId: payload.tenantId, organizationId: payload.organizationId }\n\n void Promise.resolve().then(async () => {\n try {\n await bus.emitEvent('query_index.reindex', payload, { persistent: true })\n if (this.isDebugVerbosity()) this.debug('query:auto-reindex:scheduled', context)\n } catch (err) {\n logger.warn('Failed to schedule auto reindex', { ...context, err })\n }\n })\n }\n\n private scheduleCoverageRefresh(\n entity: string,\n tenantId: string | null | undefined,\n organizationId: string | null | undefined,\n withDeleted: boolean\n ): void {\n const bus = this.resolveEventBus()\n if (!bus) return\n const key = [entity, tenantId ?? '__tenant__', organizationId ?? '__org__', withDeleted ? '1' : '0'].join('|')\n if (this.pendingCoverageRefreshKeys.has(key)) return\n this.pendingCoverageRefreshKeys.add(key)\n void Promise.resolve()\n .then(async () => {\n try {\n await bus.emitEvent('query_index.coverage.refresh', {\n entityType: entity,\n tenantId: tenantId ?? null, organizationId: organizationId ?? null,\n withDeleted, delayMs: 0,\n })\n if (this.isDebugVerbosity()) {\n this.debug('coverage:refresh:scheduled', {\n entity, tenantId: tenantId ?? null, organizationId: organizationId ?? null, withDeleted,\n })\n }\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('coverage:refresh:failed', {\n entity, tenantId: tenantId ?? null, organizationId: organizationId ?? null, withDeleted,\n error: err instanceof Error ? err.message : err,\n })\n }\n }\n })\n .finally(() => { this.pendingCoverageRefreshKeys.delete(key) })\n }\n\n private resolveEventBus(): Pick<EventBus, 'emitEvent'> | null {\n if (!this.eventBusResolver) return null\n try {\n const bus = this.eventBusResolver()\n return bus ?? null\n } catch {\n return null\n }\n }\n\n private isAutoReindexEnabled(): boolean {\n if (this.autoReindexEnabled != null) return this.autoReindexEnabled\n const raw = (process.env.SCHEDULE_AUTO_REINDEX ?? process.env.QUERY_INDEX_AUTO_REINDEX ?? '').trim().toLowerCase()\n if (!raw) { this.autoReindexEnabled = true; return true }\n const parsed = parseBooleanToken(raw)\n this.autoReindexEnabled = parsed === null ? true : parsed\n return this.autoReindexEnabled\n }\n\n private getAutoReindexDebounceMs(): number {\n if (this.autoReindexDebounceMs != null) return this.autoReindexDebounceMs\n this.autoReindexDebounceMs = parseNumberWithDefault(\n process.env.OM_QUERY_INDEX_AUTO_REINDEX_DEBOUNCE_MS,\n AUTO_REINDEX_DEBOUNCE_DEFAULT_MS,\n { integer: true, min: 0 },\n )\n return this.autoReindexDebounceMs\n }\n\n private isCoverageOptimizationEnabled(): boolean {\n if (this.coverageOptimizationEnabled != null) return this.coverageOptimizationEnabled\n const raw = (process.env.OPTIMIZE_INDEX_COVERAGE_STATS ?? '').trim().toLowerCase()\n if (!raw) { this.coverageOptimizationEnabled = false; return false }\n this.coverageOptimizationEnabled = parseBooleanToken(raw) === true\n return this.coverageOptimizationEnabled\n }\n\n private async columnExists(table: string, column: string): Promise<boolean> {\n const key = `${table}.${column}`\n if (this.columnCache.has(key)) {\n const cached = this.columnCache.get(key)\n if (cached === true) return true\n this.columnCache.delete(key)\n }\n const db = this.getDb() as any\n const exists = await db\n .selectFrom('information_schema.columns')\n .select(sql<number>`1`.as('one'))\n .where('table_name', '=', table)\n .where('column_name', '=', column)\n .executeTakeFirst()\n const present = !!exists\n if (present) this.columnCache.set(key, true)\n else this.columnCache.delete(key)\n return present\n }\n\n private async getBaseColumnsForEntity(entity: string): Promise<Map<string, string>> {\n const db = this.getDb() as any\n const table = resolveEntityTableName(this.em, entity)\n const rows = await db\n .selectFrom('information_schema.columns')\n .select(['column_name', 'data_type'])\n .where('table_name', '=', table)\n .execute() as Array<{ column_name: string; data_type: string }>\n const map = new Map<string, string>()\n for (const r of rows) map.set(r.column_name, r.data_type)\n return map\n }\n\n private resolveOrganizationScope(opts: QueryOptions): { ids: string[]; includeNull: boolean } | null {\n if (opts.organizationIds !== undefined) {\n const raw = (opts.organizationIds ?? []).map((id) => (typeof id === 'string' ? id.trim() : id))\n const includeNull = raw.some((id) => id == null || id === '')\n const ids = raw.filter((id): id is string => typeof id === 'string' && id.length > 0)\n const unique = Array.from(new Set(ids))\n return { ids: unique, includeNull }\n }\n if (typeof opts.organizationId === 'string' && opts.organizationId.trim().length > 0) {\n return { ids: [opts.organizationId], includeNull: false }\n }\n return null\n }\n\n private resolveCoverageSnapshotScope(\n opts: QueryOptions\n ): { tenantId: string | null; organizationId: string | null } | null {\n const tenantId = opts.tenantId ?? null\n const orgScope = this.resolveOrganizationScope(opts)\n if (!orgScope) return { tenantId, organizationId: null }\n if (orgScope.includeNull) {\n if (orgScope.ids.length === 0) return { tenantId, organizationId: null }\n return null\n }\n if (orgScope.ids.length === 1) return { tenantId, organizationId: orgScope.ids[0] }\n if (orgScope.ids.length === 0) return { tenantId, organizationId: null }\n return null\n }\n\n private applyOrganizationScope(\n q: AnyBuilder,\n column: string,\n scope: { ids: string[]; includeNull: boolean }\n ): AnyBuilder {\n if (scope.ids.length === 0 && !scope.includeNull) {\n return q.where(sql<boolean>`1 = 0`)\n }\n return q.where((eb: any) => {\n const parts: any[] = []\n if (scope.ids.length > 0) parts.push(eb(column, 'in', scope.ids))\n if (scope.includeNull) parts.push(eb(column, 'is', null))\n if (parts.length === 1) return parts[0]\n return eb.or(parts)\n })\n }\n\n private normalizeFilters(filters?: QueryOptions['filters']): NormalizedFilter[] {\n if (!filters) return []\n const normalizeField = (k: string) => k.startsWith('cf_') ? `cf:${k.slice(3)}` : k\n if (Array.isArray(filters)) {\n return (filters as Filter[]).map((filter) => ({\n field: normalizeField(String(filter.field)),\n op: filter.op, value: filter.value,\n }))\n }\n const out: NormalizedFilter[] = []\n const obj = filters as Record<string, unknown>\n const add = (field: string, op: FilterOp, value?: unknown) => out.push({ field, op, value })\n for (const [rawKey, rawVal] of Object.entries(obj)) {\n const field = normalizeField(rawKey)\n if (rawVal !== null && typeof rawVal === 'object' && !Array.isArray(rawVal)) {\n for (const [opKey, opVal] of Object.entries(rawVal as Record<string, unknown>)) {\n switch (opKey) {\n case '$eq': add(field, 'eq', opVal); break\n case '$ne': add(field, 'ne', opVal); break\n case '$gt': add(field, 'gt', opVal); break\n case '$gte': add(field, 'gte', opVal); break\n case '$lt': add(field, 'lt', opVal); break\n case '$lte': add(field, 'lte', opVal); break\n case '$in': add(field, 'in', opVal); break\n case '$nin': add(field, 'nin', opVal); break\n case '$like': add(field, 'like', opVal); break\n case '$ilike': add(field, 'ilike', opVal); break\n case '$exists': add(field, 'exists', opVal); break\n }\n }\n } else {\n add(field, 'eq', rawVal)\n }\n }\n return out\n }\n\n private sanitize(s: string): string {\n return s.replace(/[^a-zA-Z0-9_]/g, '_')\n }\n\n private toArray(value: unknown): readonly unknown[] {\n if (Array.isArray(value)) return value\n if (value === undefined) return []\n return [value]\n }\n\n private parseCount(row: unknown): number {\n if (row && typeof row === 'object' && 'count' in row) {\n const value = (row as { count: unknown }).count\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isNaN(parsed) ? 0 : parsed\n }\n if (typeof value === 'bigint') return Number(value)\n }\n return 0\n }\n\n private logSearchDebug(event: string, payload: Record<string, unknown>) {\n if (!this.isDebugVerbosity()) return\n logger.debug('Search debug event', { event, payload })\n }\n\n private applyColumnFilter(\n q: AnyBuilder,\n column: string | RawBuilder<unknown>,\n filter: NormalizedFilter,\n search?: SearchRuntime & { entity: string; field: string; recordIdColumn?: string },\n ): AnyBuilder {\n if (\n (filter.op === 'like' || filter.op === 'ilike') &&\n search?.enabled &&\n typeof filter.value === 'string' &&\n // Plaintext base columns keep exact SQL ILIKE -- see SearchRuntime.encryptedFields.\n // Membership runs across name-shape candidates: maps may declare `displayName` while the\n // filter carries the column name `display_name`.\n (search.encryptedFields == null || isEncryptedLikeField(search.encryptedFields, search.field))\n ) {\n const tokens = tokenizeText(String(filter.value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const sources: SearchTokenSource[] = (search.searchSources && search.searchSources.length\n ? search.searchSources\n : [{ entity: search.entity, recordIdColumn: search.recordIdColumn ?? '' }]\n ).filter((src) => src.recordIdColumn && src.entity)\n if (sources.length) {\n const engine = this\n q = q.where((eb: any) => eb.or(\n sources.map((src) =>\n eb.exists(engine.buildSearchTokensSub(eb, {\n entity: src.entity, field: search.field, hashes,\n recordIdColumn: src.recordIdColumn,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n ))\n this.logSearchDebug('search:filter', {\n entity: search.entity, field: search.field, tokens: tokens.tokens, hashes,\n applied: true, tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope,\n sources: sources.map((src) => ({ entity: src.entity, recordIdColumn: src.recordIdColumn })),\n })\n return q\n }\n // Hashes exist but no usable search source: same reasoning as the no-hash branch below --\n // a KNOWN-encrypted column must fail closed rather than drop the predicate (which would\n // return the full list on exactly the columns ILIKE cannot serve).\n if (search.encryptedFields != null && isEncryptedLikeField(search.encryptedFields, search.field)) {\n return q.where(sql<boolean>`false`)\n }\n } else {\n this.logSearchDebug('search:skip-empty-hashes', {\n entity: search.entity, field: search.field, value: filter.value,\n })\n // A column KNOWN to be encrypted has no way to match the term except the token index:\n // dropping the predicate would return every row for a term merely too short to tokenize.\n // Every other case (gate off, custom-entity runtime, resolution failure) keeps the\n // legacy behavior of skipping the predicate.\n if (search.encryptedFields != null && isEncryptedLikeField(search.encryptedFields, search.field)) {\n return q.where(sql<boolean>`false`)\n }\n }\n return q\n }\n const col: any = column\n switch (filter.op) {\n case 'eq':\n return filter.value === null\n ? q.where(col, 'is', null)\n : q.where(col, '=', filter.value as any)\n case 'ne':\n return filter.value === null\n ? q.where(col, 'is not', null)\n : q.where(col, '!=', filter.value as any)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = filter.op === 'gt' ? '>' : filter.op === 'gte' ? '>=' : filter.op === 'lt' ? '<' : '<='\n return q.where(col, operator, filter.value as any)\n }\n case 'in':\n return q.where(col, 'in', this.toArray(filter.value))\n case 'nin':\n return q.where(col, 'not in', this.toArray(filter.value))\n case 'like':\n return q.where(col, 'like', filter.value as any)\n case 'ilike':\n return q.where(col, 'ilike', filter.value as any)\n case 'exists':\n return filter.value ? q.where(col, 'is not', null) : q.where(col, 'is', null)\n default:\n return q\n }\n }\n\n private resolveCustomEntityColumn(alias: string, field: string): string | null {\n if (field === 'id') return `${alias}.entity_id`\n if (field === 'organization_id' || field === 'organizationId') return `${alias}.organization_id`\n if (field === 'tenant_id' || field === 'tenantId') return `${alias}.tenant_id`\n if (field === 'created_at' || field === 'updated_at' || field === 'deleted_at') return `${alias}.${field}`\n return null\n }\n\n private isDebugVerbosity(): boolean {\n if (this.debugVerbosity != null) return this.debugVerbosity\n this.debugVerbosity = resolveDebugVerbosity()\n return this.debugVerbosity\n }\n\n private isSqlDebugEnabled(): boolean {\n if (this.sqlDebugEnabled != null) return this.sqlDebugEnabled\n this.sqlDebugEnabled = resolveBooleanEnv(['QUERY_ENGINE_DEBUG_SQL'], false)\n return this.sqlDebugEnabled\n }\n\n private isForcePartialIndexEnabled(): boolean {\n if (this.forcePartialIndexEnabled != null) return this.forcePartialIndexEnabled\n this.forcePartialIndexEnabled = resolveBooleanEnv(['FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES'], false)\n return this.forcePartialIndexEnabled\n }\n\n private async resolveCoverageGap(\n entity: string,\n opts: QueryOptions,\n coverageScope?: { tenantId: string | null; organizationId: string | null } | null,\n _sourceTable?: string\n ): Promise<{ stats?: { baseCount: number; indexedCount: number }; scope: 'scoped' | 'global' } | null> {\n const scope = coverageScope ?? this.resolveCoverageSnapshotScope(opts)\n if (!scope) return null\n const tenantId = scope.tenantId\n const organizationId = scope.organizationId\n const withDeleted = !!opts.withDeleted\n\n const snapshot = await this.getStoredCoverageSnapshot(entity, tenantId, organizationId, withDeleted)\n if (!snapshot) {\n this.scheduleCoverageRefresh(entity, tenantId, organizationId, withDeleted)\n return { stats: undefined, scope: 'scoped' }\n }\n\n const baseCount = snapshot.baseCount\n const indexCount = snapshot.indexedCount\n const hasGap = baseCount > 0 && indexCount < baseCount\n if (hasGap || indexCount > baseCount) return { stats: snapshot, scope: 'scoped' }\n return null\n }\n\n // Backward-compatible hook for tests that mock coverage stats\n private async indexCoverageStats(\n entity: string,\n opts: QueryOptions,\n coverageScope?: { tenantId: string | null; organizationId: string | null } | null,\n ): Promise<{ baseCount: number; indexedCount: number } | null> {\n const gap = await this.resolveCoverageGap(entity, opts, coverageScope)\n return gap?.stats ?? null\n }\n\n private async captureSqlTiming<TResult>(\n label: string,\n entity: EntityId,\n execute: () => Promise<TResult> | TResult,\n extra?: Record<string, unknown>,\n profiler?: Profiler\n ): Promise<TResult> {\n const shouldDebug = this.isSqlDebugEnabled() && this.isDebugVerbosity()\n const shouldProfile = profiler?.enabled === true\n if (!shouldDebug && !shouldProfile) return Promise.resolve(execute())\n const startedAt = process.hrtime.bigint()\n try {\n return await Promise.resolve(execute())\n } finally {\n const elapsedMs = Number(process.hrtime.bigint() - startedAt) / 1_000_000\n const context: Record<string, unknown> = { entity, durationMs: Math.round(elapsedMs * 1000) / 1000 }\n if (extra) Object.assign(context, extra)\n if (shouldProfile) profiler!.record(label, context.durationMs as number, extra)\n if (shouldDebug) this.debug(`${label}:timing`, context)\n }\n }\n\n private debug(message: string, context?: Record<string, unknown>): void {\n if (!this.isDebugVerbosity()) return\n if (!this.isSqlDebugEnabled()) return\n if (context) logger.debug(message, context)\n else logger.debug(message)\n }\n}\n"],
|
|
5
|
-
"mappings": "AACA,SAAS,eAAe;AAGxB,SAA2B,wBAAwB,wCAAwC;AAC3F,SAAS,iCAAiC;AAC1C,SAAsB,WAA4B;AAElD,SAAS,sBAAsB,+BAA+B;AAC9D,SAAS,gBAAgB,4BAA2C;AAEpE,SAAS,mCAAmC;AAC5C,SAAS,mBAAmB,+BAA+B;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,2BAA8C;AACvD,SAAS,sBAAsB,oCAAoC;AACnE,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB,6BAAyD;AAC1F,SAAS,oCAAoC;AAC7C,SAAS,4BAA4B,6BAA6B,wBAAwB;AAC1F,SAAS,2BAA2B;AACpC,SAAS,0BAA0B;AACnC,SAAS,oBAAoB;AAC7B,SAAS,8BA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MAAO,QAAO,OAAO,SAAS,KAAK;AACvC,UAAI,cAAe,UAAU,OAAO,OAAO,QAAQ,YAAsB,KAAK;AAC9E,UAAI,YAAa,MAAK,MAAM,GAAG,KAAK,WAAW,OAAO;AAAA,IACxD;AAAA,EACF;AAAA,EAEQ,MAAM,SAAiB,SAAyC;AACtE,QAAI,CAAC,KAAK,iBAAiB,EAAG;AAC9B,QAAI,CAAC,KAAK,kBAAkB,EAAG;AAC/B,QAAI,QAAS,QAAO,MAAM,SAAS,OAAO;AAAA,QACrC,QAAO,MAAM,OAAO;AAAA,EAC3B;AACF;",
|
|
4
|
+
"sourcesContent": ["import type { QueryEngine, QueryOptions, QueryResult, QueryResultMeta, EncryptedSortRowCapWarning, FilterOp, Filter, QueryCustomFieldSource, PartialIndexWarning, QueryExtensionsConfig, Sort } from '@open-mercato/shared/lib/query/types'\nimport { SortDir } from '@open-mercato/shared/lib/query/types'\nimport type { EntityId } from '@open-mercato/shared/modules/entities'\nimport type { EntityManager } from '@mikro-orm/postgresql'\nimport { BasicQueryEngine, resolveEntityTableName, resolveRegisteredEntityTableName } from '@open-mercato/shared/lib/query/engine'\nimport { isOrmBackedSystemEntityId } from '@open-mercato/shared/lib/data/engine'\nimport { type Kysely, sql, type RawBuilder } from 'kysely'\nimport type { EventBus } from '@open-mercato/events'\nimport { readCoverageSnapshot, refreshCoverageSnapshot } from './coverage'\nimport { createProfiler, shouldEnableProfiler, type Profiler } from '@open-mercato/shared/lib/profiler'\nimport type { VectorIndexService } from '@open-mercato/search/vector'\nimport { decryptIndexDocCustomFields } from '@open-mercato/shared/lib/encryption/indexDoc'\nimport { parseBooleanToken, parseBooleanWithDefault } from '@open-mercato/shared/lib/boolean'\nimport {\n applyJoinFilters,\n normalizeFilters,\n partitionFilters,\n resolveJoins,\n type BaseFilter,\n type ResolvedJoin,\n} from '@open-mercato/shared/lib/query/join-utils'\nimport { resolveSearchConfig, type SearchConfig } from '@open-mercato/shared/lib/search/config'\nimport {\n createSearchTokenAvailability,\n isSearchFilterOp,\n hasSearchFilter,\n type SearchTokenAvailability,\n type SearchTokenProbeDb,\n type SearchTokenProbeQueryBuilder,\n} from '@open-mercato/shared/lib/search/availability'\nimport { tokenizeText } from '@open-mercato/shared/lib/search/tokenize'\nimport { runBeforeQueryPipeline, runAfterQueryPipeline, type QueryExtensionContext } from '@open-mercato/shared/lib/query/query-extension-runner'\nimport { warnOnCiphertextLikeFallback } from '@open-mercato/shared/lib/query/ciphertext-search-warning'\nimport { resolveEncryptedSortFields, resolveEncryptedSortMaxRows, sortRowsInMemory } from '@open-mercato/shared/lib/query/encrypted-sort'\nimport { mapWithConcurrency } from '@open-mercato/shared/lib/query/bounded-decrypt'\nimport { createLogger } from '@open-mercato/shared/lib/logger'\nimport { parseNumberWithDefault } from '@open-mercato/shared/lib/number'\n\nconst logger = createLogger('query_index').child({ component: 'engine' })\n\n/** Operators `buildCfFilterExpression` compiles; anything else yields no predicate. */\nconst CF_FILTER_SUPPORTED_OPS = new Set<FilterOp>([\n 'eq', 'ne', 'in', 'nin', 'like', 'ilike', 'exists', 'gt', 'gte', 'lt', 'lte',\n])\n\nconst DECRYPT_CONCURRENCY = 8\nconst AUTO_REINDEX_DEBOUNCE_DEFAULT_MS = 30_000\nconst AUTO_REINDEX_DEBOUNCE_MAX_SCOPES = 10_000\nconst AUTO_REINDEX_SCHEDULED_AT_KEY = Symbol.for('@open-mercato/query-index/auto-reindex-scheduled-at')\n\ntype GlobalWithAutoReindexSchedule = typeof globalThis & {\n [AUTO_REINDEX_SCHEDULED_AT_KEY]?: Map<string, number>\n}\n\nfunction getAutoReindexScheduledAt(): Map<string, number> {\n const globalScope = globalThis as GlobalWithAutoReindexSchedule\n if (!globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY]) {\n globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY] = new Map<string, number>()\n }\n return globalScope[AUTO_REINDEX_SCHEDULED_AT_KEY]\n}\n\nfunction markAutoReindexScheduled(key: string, debounceMs: number, now: number): boolean {\n const autoReindexScheduledAt = getAutoReindexScheduledAt()\n const previous = autoReindexScheduledAt.get(key)\n if (previous !== undefined && now - previous < debounceMs) return false\n\n if (autoReindexScheduledAt.size >= AUTO_REINDEX_DEBOUNCE_MAX_SCOPES) {\n for (const [scopeKey, scheduledAt] of autoReindexScheduledAt) {\n if (now - scheduledAt >= debounceMs) autoReindexScheduledAt.delete(scopeKey)\n }\n if (autoReindexScheduledAt.size >= AUTO_REINDEX_DEBOUNCE_MAX_SCOPES) {\n const oldestKey = autoReindexScheduledAt.keys().next().value\n if (oldestKey !== undefined) autoReindexScheduledAt.delete(oldestKey)\n }\n }\n\n autoReindexScheduledAt.delete(key)\n autoReindexScheduledAt.set(key, now)\n return true\n}\n\nfunction buildFilterableCustomFieldJoins(\n sources: QueryCustomFieldSource[] | undefined,\n): Array<{\n alias: string\n table?: string\n entityId: EntityId\n from: { field: string }\n to: { field: string }\n type: 'left' | 'inner'\n}> {\n if (!sources || sources.length === 0) return []\n return sources.flatMap((source, index) => {\n if (!source.join) return []\n const alias = typeof source.alias === 'string' && source.alias.trim().length > 0\n ? source.alias.trim()\n : `cfs_${index}`\n return [{\n alias,\n table: source.table,\n entityId: source.entityId,\n from: { field: source.join.fromField },\n to: { field: source.join.toField },\n type: source.join.type === 'inner' ? 'inner' : 'left',\n }]\n })\n}\n\nfunction resolveBooleanEnv(names: readonly string[], defaultValue: boolean): boolean {\n for (const name of names) {\n const raw = process.env[name]\n if (raw !== undefined) return parseBooleanWithDefault(raw, defaultValue)\n }\n return defaultValue\n}\n\nexport function coerceSortDirection(dir: unknown): SortDir {\n return String(dir ?? SortDir.Asc).toLowerCase() === SortDir.Desc ? SortDir.Desc : SortDir.Asc\n}\n\nfunction resolveDebugVerbosity(): boolean {\n const queryIndexDebug = process.env.OM_QUERY_INDEX_DEBUG\n if (queryIndexDebug !== undefined) {\n return parseBooleanToken(queryIndexDebug) ?? false\n }\n const level = (process.env.LOG_VERBOSITY ?? process.env.LOG_LEVEL ?? '').toLowerCase()\n if (['debug', 'trace', 'silly'].includes(level)) return true\n return false\n}\n\ntype AnyDb = Kysely<any>\ntype AnyBuilder = any\ntype NormalizedFilter = { field: string; op: FilterOp; value?: unknown }\ntype IndexDocSource = { alias: string; entityId: EntityId; recordIdColumn: string }\ntype PreparedCustomFieldSource = {\n alias: string\n indexAlias: string\n entityId: EntityId\n recordIdColumn: string\n organizationField?: string\n tenantField?: string\n table: string\n}\ntype SearchRuntime = {\n enabled: boolean\n config: SearchConfig\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n tenantId?: string | null\n searchSources?: SearchTokenSource[]\n /** Per-`query()` alias minter for `search_tokens` subqueries (see #2738). */\n mintAlias: () => string\n}\n\ntype EncryptionResolver = () => {\n decryptEntityPayload?: (entityId: EntityId, payload: Record<string, unknown>, tenantId?: string | null, organizationId?: string | null) => Promise<Record<string, unknown>>\n getEncryptedFieldNames?: (entityId: EntityId, tenantId?: string | null, organizationId?: string | null) => Promise<readonly string[]>\n isEnabled?: () => boolean\n} | null\n\ntype SearchTokenSource = { entity: string; recordIdColumn: string }\n\n/**\n * Mints `search_tokens` subquery aliases (`st_0`, `st_1`, \u2026). Aliases only need\n * to be unique within a single SQL statement, so every `query()` invocation owns\n * a fresh minter. Keeping the counter call-local (rather than on the shared\n * engine instance) means concurrent queries can never reset or collide on each\n * other's sequence (#2738).\n */\nfunction createSearchAliasMinter(): () => string {\n let seq = 0\n return () => `st_${seq++}`\n}\n\nfunction createQueryProfiler(entity: string): Profiler {\n const enabled = shouldEnableProfiler(entity)\n return createProfiler({\n scope: 'query_engine',\n target: entity,\n label: `query_engine:${entity}`,\n loggerLabel: '[qe:profile]',\n enabled,\n })\n}\n\nexport class HybridQueryEngine implements QueryEngine {\n private coverageStatsTtlMs: number\n private customFieldKeysCache = new Map<string, { expiresAt: number; value: string[] }>()\n private customFieldKeysTtlMs: number\n private columnCache = new Map<string, boolean>()\n private customEntityCache = new Map<string, boolean>()\n private debugVerbosity: boolean | null = null\n private sqlDebugEnabled: boolean | null = null\n private forcePartialIndexEnabled: boolean | null = null\n private autoReindexEnabled: boolean | null = null\n private autoReindexDebounceMs: number | null = null\n private coverageOptimizationEnabled: boolean | null = null\n private pendingCoverageRefreshKeys = new Set<string>()\n private searchAvailabilityInstance: SearchTokenAvailability | null = null\n\n constructor(\n private em: EntityManager,\n private fallback: BasicQueryEngine,\n private eventBusResolver?: () => Pick<EventBus, 'emitEvent'> | null | undefined,\n private vectorServiceResolver?: () => VectorIndexService | null | undefined,\n private encryptionResolver?: EncryptionResolver,\n ) {\n const coverageTtl = Number.parseInt(process.env.QUERY_INDEX_COVERAGE_CACHE_MS ?? '', 10)\n this.coverageStatsTtlMs = Number.isFinite(coverageTtl) && coverageTtl >= 0 ? coverageTtl : 5 * 60 * 1000\n const cfTtl = Number.parseInt(process.env.QUERY_INDEX_CF_KEYS_CACHE_MS ?? '', 10)\n this.customFieldKeysTtlMs = Number.isFinite(cfTtl) && cfTtl >= 0 ? cfTtl : 5 * 60 * 1000\n }\n\n private getEncryptionService() {\n try {\n return this.encryptionResolver?.() ?? null\n } catch {\n return null\n }\n }\n\n private getDb(): AnyDb {\n const emAny = this.em as any\n if (typeof emAny.getKysely === 'function') return emAny.getKysely() as AnyDb\n throw new Error('HybridQueryEngine requires an EntityManager exposing getKysely() (MikroORM v7)')\n }\n\n private searchAvailability(): SearchTokenAvailability {\n if (!this.searchAvailabilityInstance) {\n this.searchAvailabilityInstance = createSearchTokenAvailability({\n getDb: () => this.getDb() as unknown as SearchTokenProbeDb,\n getConfig: resolveSearchConfig,\n applyOrganizationScope: (query, column, scope) => this.applyOrganizationScope(\n query as unknown as AnyBuilder,\n column,\n scope,\n ) as unknown as SearchTokenProbeQueryBuilder,\n logDebug: (event, payload) => this.logSearchDebug(event, payload),\n })\n }\n return this.searchAvailabilityInstance\n }\n\n async query<T = unknown>(entity: EntityId, opts: QueryOptions = {}): Promise<QueryResult<T>> {\n const ext: QueryExtensionsConfig | undefined = opts.extensions\n let hybridExtCtx: QueryExtensionContext | null = null\n const noopDi = { resolve: <R = unknown>(_name: string): R => { throw new Error('No DI context') } }\n\n if (ext) {\n hybridExtCtx = {\n entity: String(entity),\n engine: 'hybrid',\n tenantId: opts.tenantId ?? '',\n organizationId: opts.organizationId,\n userId: ext.userId,\n em: this.em,\n container: ext.container,\n userFeatures: ext.userFeatures,\n }\n const diCtx = ext.resolve ? { resolve: ext.resolve } : noopDi\n const beforeResult = await runBeforeQueryPipeline(opts, hybridExtCtx, diCtx)\n if (beforeResult.blocked) {\n throw new Error(beforeResult.errorMessage ?? 'Query blocked by extension subscriber')\n }\n opts = beforeResult.query\n }\n const { extensions: _stripExt, ...coreOpts } = opts\n opts = coreOpts\n\n const providedProfiler = opts.profiler\n const profiler = providedProfiler && providedProfiler.enabled\n ? providedProfiler\n : createQueryProfiler(String(entity))\n profiler.mark('query:init')\n let profileClosed = false\n const finishProfile = (meta?: Record<string, unknown>) => {\n if (!profiler.enabled || profileClosed) return\n profileClosed = true\n profiler.end(meta)\n }\n\n const applyAfterExtensions = async <R>(queryResult: QueryResult<R>): Promise<QueryResult<R>> => {\n if (!ext || !hybridExtCtx) return queryResult\n const diCtx = ext.resolve ? { resolve: ext.resolve } : noopDi\n return await runAfterQueryPipeline(\n queryResult as QueryResult<Record<string, unknown>>,\n opts,\n hybridExtCtx,\n diCtx,\n ) as QueryResult<R>\n }\n\n try {\n const debugEnabled = this.isDebugVerbosity()\n if (debugEnabled) this.debug('query:start', { entity })\n\n const isCustom = opts.forceCustomEntityStorage === true || await this.isCustomEntity(entity)\n if (isCustom) {\n if (debugEnabled) this.debug('query:custom-entity', { entity })\n const section = profiler.section('custom_entity')\n try {\n const result = await this.queryCustomEntity<T>(entity, opts)\n section.end({ mode: 'custom_entity' })\n finishProfile({\n result: 'custom_entity',\n total: Array.isArray(result.items) ? result.items.length : undefined,\n })\n return await applyAfterExtensions(result)\n } catch (err) {\n section.end({ error: err instanceof Error ? err.message : String(err) })\n throw err\n }\n }\n\n const db = this.getDb()\n profiler.mark('query:db_ready')\n const baseTable = resolveEntityTableName(this.em, entity)\n profiler.mark('query:base_table_resolved')\n const searchConfig = resolveSearchConfig()\n const orgScope = this.resolveOrganizationScope(opts)\n const searchEnabled = await this.searchAvailability().staticEnabled()\n\n const baseExists = await profiler.measure('base_table_exists', () => this.tableExists(baseTable))\n if (!baseExists) {\n if (debugEnabled) this.debug('query:fallback:missing-base', { entity, baseTable })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'missing_base' })\n return await applyAfterExtensions(fallbackResult)\n }\n\n if (opts.omitAutomaticTenantOrgScope === true) {\n if (debugEnabled) this.debug('query:fallback:omit-automatic-scope', { entity })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'omit_automatic_tenant_org_scope' })\n return await applyAfterExtensions(fallbackResult)\n }\n\n const normalizedFilters = normalizeFilters(opts.filters)\n const cfFilters = normalizedFilters.filter((filter) => filter.field.startsWith('cf:') || filter.field.startsWith('l10n:'))\n const coverageScope = this.resolveCoverageSnapshotScope(opts)\n const wantsCf = (\n (opts.fields || []).some((field) => typeof field === 'string' && (field.startsWith('cf:') || field.startsWith('l10n:'))) ||\n cfFilters.length > 0 ||\n (Array.isArray(opts.includeCustomFields) && opts.includeCustomFields.length > 0)\n )\n\n if (debugEnabled) {\n this.debug('query:config', {\n entity,\n wantsCustomFields: wantsCf,\n customFieldSources: Array.isArray(opts.customFieldSources) ? opts.customFieldSources.map((src) => src?.entityId) : undefined,\n fields: opts.fields,\n })\n }\n\n let partialIndexWarning: PartialIndexWarning | null = null\n let entityHasActiveCustomFields = true\n\n if (wantsCf) {\n entityHasActiveCustomFields = await this.entityHasActiveCustomFields(entity, opts.tenantId ?? null)\n const hasIndexRows = await profiler.measure(\n 'index_any_rows',\n () => this.indexAnyRows(entity),\n (value) => ({ hasIndexRows: value })\n )\n if (!hasIndexRows) {\n if (debugEnabled) this.debug('query:fallback:no-index', { entity })\n const fallbackResult = await this.fallback.query(entity, opts)\n finishProfile({ result: 'fallback', reason: 'no_index_rows' })\n return await applyAfterExtensions(fallbackResult)\n }\n if (entityHasActiveCustomFields) {\n const gap = await profiler.measure(\n 'resolve_coverage_gap',\n () => this.resolveCoverageGap(entity, opts, coverageScope),\n (value) => (value\n ? {\n scope: value.scope,\n baseCount: value.stats?.baseCount ?? null,\n indexedCount: value.stats?.indexedCount ?? null,\n }\n : { scope: null })\n )\n if (gap) {\n if (!opts.skipAutoReindex) {\n this.scheduleAutoReindex(entity, opts, gap.stats, coverageScope?.organizationId ?? null)\n }\n const force = this.isForcePartialIndexEnabled()\n if (!force) {\n if (gap.stats) {\n logger.warn('Partial index coverage detected; falling back to basic engine', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n if (debugEnabled) this.debug('query:fallback:partial-coverage', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n } else {\n logger.warn('Partial index coverage detected; falling back to basic engine', { entity })\n if (debugEnabled) this.debug('query:fallback:partial-coverage', { entity })\n }\n const fallbackResult = await this.fallback.query(entity, opts)\n const resultWithWarning: QueryResult<T> = {\n ...fallbackResult,\n meta: {\n ...(fallbackResult.meta ?? {}),\n partialIndexWarning: {\n entity,\n entityLabel: this.resolveEntityLabel(entity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n },\n },\n }\n finishProfile({\n result: 'fallback',\n reason: 'partial_index',\n scope: gap.scope,\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n })\n return await applyAfterExtensions(resultWithWarning)\n }\n if (gap.stats) {\n logger.warn('Partial index coverage detected; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n } else {\n logger.warn('Partial index coverage detected; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity })\n }\n partialIndexWarning = {\n entity,\n entityLabel: this.resolveEntityLabel(entity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n }\n }\n } else if (debugEnabled) {\n this.debug('query:coverage:skip-no-custom-fields', { entity })\n }\n }\n\n const qualify = (col: string) => `b.${col}`\n const columns = await this.getBaseColumnsForEntity(entity)\n const hasOrganizationColumn = await this.columnExists(baseTable, 'organization_id')\n const hasTenantColumn = await this.columnExists(baseTable, 'tenant_id')\n const hasDeletedColumn = await this.columnExists(baseTable, 'deleted_at')\n\n if (!opts.tenantId) throw new Error('QueryEngine: tenantId is required')\n\n const resolvedJoinsConfig = resolveJoins(\n baseTable,\n [...(opts.joins ?? []), ...buildFilterableCustomFieldJoins(opts.customFieldSources)],\n (entityId) => resolveEntityTableName(this.em, entityId as any),\n )\n const joinMap = new Map<string, ResolvedJoin>()\n const aliasTables = new Map<string, string>()\n aliasTables.set('b', baseTable)\n aliasTables.set('base', baseTable)\n aliasTables.set(baseTable, baseTable)\n for (const join of resolvedJoinsConfig) {\n joinMap.set(join.alias, join)\n aliasTables.set(join.alias, join.table)\n }\n const { baseFilters, joinFilters } = partitionFilters(baseTable, normalizedFilters, joinMap)\n\n const searchRuntimeBase = {\n enabled: false,\n config: searchConfig,\n organizationScope: orgScope,\n tenantId: opts.tenantId ?? null,\n mintAlias: createSearchAliasMinter(),\n }\n\n // Prepare index sources for JSONB custom-field access.\n const indexSources: IndexDocSource[] = [{ alias: 'ei', entityId: entity, recordIdColumn: 'b.id' }]\n let preparedCfSources: PreparedCustomFieldSource[] = []\n const shouldAttachCustomSources = Array.isArray(opts.customFieldSources) && opts.customFieldSources.length > 0 && (wantsCf || searchEnabled)\n if (shouldAttachCustomSources) {\n preparedCfSources = this.prepareCustomFieldSources(opts.customFieldSources ?? [])\n for (const source of preparedCfSources) {\n indexSources.push({ alias: source.indexAlias, entityId: source.entityId, recordIdColumn: `${source.alias}.${source.recordIdColumn}` })\n }\n }\n\n const searchSources: SearchTokenSource[] = indexSources\n .map((src) => ({ entity: String(src.entityId), recordIdColumn: src.recordIdColumn }))\n .filter((src) => src.recordIdColumn && src.entity)\n const searchFilters = normalizedFilters.filter((filter) => isSearchFilterOp(filter.op))\n const sourceSearchFilters = [\n ...baseFilters,\n ...normalizedFilters.filter((filter) => String(filter.field).startsWith('cf:')),\n ].filter((filter) => isSearchFilterOp(filter.op))\n // Probe `search_tokens` only when this query actually searches (#4723). Every consumer of\n // `searchRuntime.enabled` already sits behind a like/ilike guard, so on a plain list load the\n // answer is unused \u2014 and the probe is a `LIMIT 1` the planner can resolve as a seq scan over a\n // large `search_tokens`. The join path below already probes lazily for the same reason.\n const hasSearchTokens = searchEnabled && searchSources.length && sourceSearchFilters.length\n ? await this.searchAvailability().anySourceHasTokens(searchSources, opts.tenantId ?? null, orgScope)\n : false\n const searchRuntime: SearchRuntime = { ...searchRuntimeBase, searchSources, enabled: searchEnabled && hasSearchTokens }\n if (searchFilters.length) {\n this.logSearchDebug('search:init', {\n entity,\n baseTable,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n fields: searchFilters.map((filter) => String(filter.field)),\n searchEnabled,\n hasSearchTokens,\n searchSources,\n searchConfig: {\n enabled: searchConfig.enabled,\n minTokenLength: searchConfig.minTokenLength,\n enablePartials: searchConfig.enablePartials,\n hashAlgorithm: searchConfig.hashAlgorithm,\n blocklistedFields: searchConfig.blocklistedFields,\n },\n })\n if (!searchEnabled) this.logSearchDebug('search:disabled', { entity, baseTable })\n else if (!hasSearchTokens) this.logSearchDebug('search:no-search-tokens', {\n entity, baseTable,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n searchSources,\n })\n const baseSearchFilters = [...baseFilters, ...cfFilters]\n .filter((filter) => filter.op === 'like' || filter.op === 'ilike')\n const fallbackFields = baseSearchFilters\n .filter((filter) => !searchRuntime.enabled || typeof filter.value !== 'string' || tokenizeText(filter.value, searchConfig).hashes.length === 0)\n .map((filter) => String(filter.field))\n if (fallbackFields.length) {\n await warnOnCiphertextLikeFallback({\n entity: String(entity),\n fields: fallbackFields,\n tenantId: opts.tenantId ?? null,\n // `searchEnabled` also folds in the missing-table case, which is\n // \"no usable tokens\" rather than \"the operator switched search off\".\n reason: searchRuntime.enabled\n ? 'no-indexable-tokens'\n : searchConfig.enabled ? 'no-search-tokens' : 'search-disabled',\n service: this.getEncryptionService(),\n })\n }\n }\n for (const [alias, joinedFilters] of joinFilters) {\n const filters = joinedFilters.filter((entry) => entry.op === 'like' || entry.op === 'ilike')\n if (!filters.length) continue\n const join = joinMap.get(alias)\n if (!join?.entityId) continue\n const hasJoinedTokens = searchEnabled\n ? await this.searchAvailability().hasTokens(String(join.entityId), opts.tenantId ?? null, orgScope)\n : false\n const fallbackFields = filters\n .filter((filter) => !hasJoinedTokens || typeof filter.value !== 'string' || tokenizeText(filter.value, searchConfig).hashes.length === 0)\n .map((filter) => filter.column)\n if (!fallbackFields.length) continue\n await warnOnCiphertextLikeFallback({\n entity: String(join.entityId),\n fields: fallbackFields,\n tenantId: opts.tenantId ?? null,\n reason: hasJoinedTokens\n ? 'no-indexable-tokens'\n : searchConfig.enabled ? 'no-search-tokens' : 'search-disabled',\n service: this.getEncryptionService(),\n })\n }\n const hasNonBaseSearchSource = searchSources.some(\n (src) => src.entity !== String(entity) || src.recordIdColumn !== 'b.id'\n )\n\n // Additional partial-coverage checks for customFieldSources\n if (!partialIndexWarning && Array.isArray(opts.customFieldSources) && opts.customFieldSources.length > 0 && this.isForcePartialIndexEnabled()) {\n const seen = new Set<string>([entity])\n for (const source of opts.customFieldSources) {\n const targetEntity = source?.entityId ? String(source.entityId) : null\n if (!targetEntity || seen.has(targetEntity)) continue\n seen.add(targetEntity)\n const sourceHasCustomFields = await this.entityHasActiveCustomFields(targetEntity, opts.tenantId ?? null)\n if (!sourceHasCustomFields) {\n if (debugEnabled) this.debug('query:coverage:skip-no-custom-fields', { entity: targetEntity })\n continue\n }\n const sourceTable = source.table ?? resolveEntityTableName(this.em, targetEntity)\n try {\n const gap = await profiler.measure(\n 'resolve_coverage_gap',\n () => this.resolveCoverageGap(targetEntity, opts, coverageScope, sourceTable),\n (value) => (value\n ? {\n entity: targetEntity, scope: value.scope,\n baseCount: value.stats?.baseCount ?? null,\n indexedCount: value.stats?.indexedCount ?? null,\n }\n : { entity: targetEntity, scope: null })\n )\n if (!gap) continue\n if (!opts.skipAutoReindex) {\n this.scheduleAutoReindex(targetEntity, opts, gap.stats, coverageScope?.organizationId ?? null)\n }\n partialIndexWarning = {\n entity: targetEntity,\n entityLabel: this.resolveEntityLabel(targetEntity),\n baseCount: gap.stats?.baseCount ?? null,\n indexedCount: gap.stats?.indexedCount ?? null,\n scope: gap.stats ? gap.scope : undefined,\n }\n if (debugEnabled) {\n if (gap.stats) this.debug('query:partial-coverage:forced', { entity: targetEntity, baseCount: gap.stats.baseCount, indexedCount: gap.stats.indexedCount, scope: gap.scope })\n else this.debug('query:partial-coverage:forced', { entity: targetEntity })\n }\n break\n } catch (err) {\n if (debugEnabled) this.debug('query:partial-coverage:check-failed', { entity: targetEntity, error: err instanceof Error ? err.message : err })\n }\n }\n }\n\n if (\n !partialIndexWarning &&\n wantsCf &&\n entityHasActiveCustomFields &&\n this.isForcePartialIndexEnabled() &&\n opts.tenantId\n ) {\n try {\n await this.indexCoverageStats(entity, opts, coverageScope)\n const globalStats = await this.indexCoverageStats(entity, opts, coverageScope)\n if (globalStats) {\n const globalBase = globalStats.baseCount\n const globalIndexed = globalStats.indexedCount\n const globalGap = (globalBase > 0 && globalIndexed < globalBase) || globalIndexed > globalBase\n if (globalGap) {\n logger.warn('Partial index coverage detected at global scope; forcing query index usage due to FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES', { entity, baseCount: globalBase, indexedCount: globalIndexed, scope: 'global' })\n if (debugEnabled) this.debug('query:partial-coverage:forced', { entity, baseCount: globalBase, indexedCount: globalIndexed, scope: 'global' })\n partialIndexWarning = {\n entity, entityLabel: this.resolveEntityLabel(entity),\n baseCount: globalBase, indexedCount: globalIndexed, scope: 'global',\n }\n }\n }\n } catch (err) {\n if (debugEnabled) this.debug('query:partial-coverage:global-check-failed', { entity, error: err instanceof Error ? err.message : err })\n }\n }\n\n const resolveBaseColumn = (field: string): string | null => {\n if (columns.has(field)) return field\n if (field === 'organization_id' && columns.has('id')) return 'id'\n return null\n }\n const fallbackOrgId =\n opts.organizationId\n ?? (Array.isArray(opts.organizationIds) && opts.organizationIds.length === 1 ? opts.organizationIds[0] : null)\n const encSvc = this.getEncryptionService()\n const resolvedSorts: Sort[] = []\n for (const sort of opts.sort || []) {\n const field = String(sort.field)\n if (field.startsWith('cf:')) {\n resolvedSorts.push({ ...sort, field })\n } else {\n const baseField = resolveBaseColumn(field)\n if (baseField) resolvedSorts.push({ ...sort, field: baseField })\n }\n }\n const encryptedSortFields = await resolveEncryptedSortFields(\n encSvc,\n entity,\n resolvedSorts.filter((sort) => !sort.field.startsWith('cf:')).map((sort) => sort.field),\n opts.tenantId ?? null,\n fallbackOrgId,\n )\n const requiresPlaintextSort = encryptedSortFields.size > 0\n\n // \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n // Build a reusable \"applyQueryShape\" function that applies every\n // WHERE/JOIN/scope to a fresh SelectQueryBuilder. We use this in\n // place of knex's `.clone()` for producing count + data queries.\n // \u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\n\n const applyBaseScope = (q: AnyBuilder): AnyBuilder => {\n let next = q\n if (orgScope && hasOrganizationColumn) {\n next = this.applyOrganizationScope(next, qualify('organization_id'), orgScope)\n }\n if (hasTenantColumn) {\n next = next.where(qualify('tenant_id'), '=', opts.tenantId)\n }\n if (!opts.withDeleted && hasDeletedColumn) {\n next = next.where(qualify('deleted_at'), 'is', null)\n }\n return next\n }\n\n const applyEntityIndexesJoin = (q: AnyBuilder): AnyBuilder => {\n return q.leftJoin('entity_indexes as ei', (jb: any) => {\n let jc = jb\n .on('ei.entity_type', '=', String(entity))\n .onRef('ei.entity_id', '=', sql<string>`(${sql.ref(qualify('id'))}::text)`)\n if (hasOrganizationColumn) {\n jc = jc\n .onRef('ei.organization_id', '=', qualify('organization_id'))\n .on('ei.organization_id', 'is not', null)\n }\n if (hasTenantColumn) {\n jc = jc\n .onRef('ei.tenant_id', '=', qualify('tenant_id'))\n .on('ei.tenant_id', 'is not', null)\n }\n if (!opts.withDeleted) {\n jc = jc.on('ei.deleted_at', 'is', null)\n }\n return jc\n })\n }\n\n const applyCustomFieldSourceJoins = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const source of preparedCfSources) {\n const join = (opts.customFieldSources ?? []).find((s) => s && (s.alias ?? undefined) === source.alias)?.join\n if (!join) continue\n const joinType = (join.type ?? 'left') === 'inner' ? 'innerJoin' : 'leftJoin'\n next = (next as any)[joinType](`${source.table} as ${source.alias}`, (jb: any) =>\n jb.onRef(`${source.alias}.${join.toField}`, '=', qualify(join.fromField)))\n // Index join for source\n next = next.leftJoin(`entity_indexes as ${source.indexAlias}`, (jb: any) => {\n let jc = jb\n .on(`${source.indexAlias}.entity_type`, '=', String(source.entityId))\n .onRef(`${source.indexAlias}.entity_id`, '=', sql<string>`(${sql.ref(`${source.alias}.${source.recordIdColumn}`)}::text)`)\n const orgRef = source.organizationField\n ? `${source.alias}.${source.organizationField}`\n : (columns.has('organization_id') ? qualify('organization_id') : null)\n if (orgRef) {\n jc = jc\n .onRef(`${source.indexAlias}.organization_id`, '=', orgRef)\n .on(`${source.indexAlias}.organization_id`, 'is not', null)\n }\n const tenantRef = source.tenantField\n ? `${source.alias}.${source.tenantField}`\n : (columns.has('tenant_id') ? qualify('tenant_id') : null)\n if (tenantRef) {\n jc = jc\n .onRef(`${source.indexAlias}.tenant_id`, '=', tenantRef)\n .on(`${source.indexAlias}.tenant_id`, 'is not', null)\n }\n if (!opts.withDeleted) jc = jc.on(`${source.indexAlias}.deleted_at`, 'is', null)\n return jc\n })\n }\n return next\n }\n\n // Custom-field leaves that belong to an OR disjunct are handled together with\n // the base ones below; applying them here would AND them onto every disjunct.\n const regularCfFilters = cfFilters.filter((filter) => !filter.orGroup)\n const orGroupCfFilters = cfFilters.filter((filter) => filter.orGroup)\n\n const applyCfFilters = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const filter of regularCfFilters) {\n next = this.applyCfFilterAcrossSources(\n next, filter.field, filter.op, filter.value, indexSources, searchRuntime,\n )\n }\n return next\n }\n\n const regularBaseFilters = baseFilters.filter((filter) => !filter.orGroup)\n const orGroupFilters = baseFilters.filter((filter) => filter.orGroup)\n\n const applyRegularBaseFilters = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const filter of regularBaseFilters) {\n const fieldName = String(filter.field)\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) {\n next = this.applyIndexDocFilterFromAlias(\n next, 'ei', entity, fieldName, filter.op, filter.value, 'b.id', searchRuntime,\n )\n continue\n }\n const column = qualify(baseField)\n next = this.applyColumnFilter(next, column, filter, {\n ...searchRuntime,\n entity, field: fieldName, recordIdColumn: 'b.id',\n })\n }\n return next\n }\n\n // Also used by the optimized count path, which builds from a bare base table with\n // no index/custom-field joins. Emitting a cf predicate there would reference an\n // alias that query has never joined, so this stays safe only while\n // `canOptimizeCount` is false whenever any cf filter exists (see `hasCustomFieldFilters`).\n const applyOrGroupedBaseFilters = (q: AnyBuilder): AnyBuilder => {\n if (orGroupFilters.length === 0 && orGroupCfFilters.length === 0) return q\n // `BaseFilter` here is just the normalized-leaf shape; the `cf` bucket holds\n // custom-field leaves, which never resolve to a base column.\n const groups = new Map<string, { base: BaseFilter[]; cf: BaseFilter[] }>()\n const bucketFor = (orGroup: string) => {\n const existing = groups.get(orGroup) ?? { base: [], cf: [] }\n groups.set(orGroup, existing)\n return existing\n }\n for (const filter of orGroupFilters) {\n if (!filter.orGroup) continue\n bucketFor(filter.orGroup).base.push(filter)\n }\n // Custom-field leaves belong to the same disjunct as the base ones sharing\n // their orGroup, so a mixed `base OR cf` filter unites rather than intersects.\n for (const filter of orGroupCfFilters) {\n if (!filter.orGroup) continue\n bucketFor(filter.orGroup).cf.push(filter)\n }\n // A cf leaf that compiles to no predicate is dropped, and a disjunct left with\n // no leaves is dropped too \u2014 an empty AND would read as TRUE and widen the result.\n const applicableGroups = Array.from(groups.values())\n .map((group) => ({\n base: group.base,\n cf: group.cf.filter((filter) =>\n this.cfFilterHasPredicate(filter.op, filter.value, indexSources, searchRuntime),\n ),\n }))\n .filter((group) => group.base.length > 0 || group.cf.length > 0)\n if (applicableGroups.length === 0) return q\n // Combine all groups in a single WHERE: disjuncts are OR'd together; within\n // each disjunct, fields are AND'd. Building this as separate `.where()` calls\n // would AND the disjuncts (wrong semantics).\n return q.where((eb: any) => {\n const disjuncts = applicableGroups.map((groupFilters) => {\n const parts = [\n ...groupFilters.base.map((filter) =>\n this.buildBaseFilterExpression(eb, filter, resolveBaseColumn, qualify, entity, searchRuntime),\n ),\n ...groupFilters.cf.map((filter) =>\n this.buildCfFilterExpression(\n eb, filter.field, filter.op, filter.value, indexSources, searchRuntime,\n ),\n ),\n ]\n return parts.length === 1 ? parts[0] : eb.and(parts)\n })\n return disjuncts.length === 1 ? disjuncts[0] : eb.or(disjuncts)\n })\n }\n\n const applyAliasScopes = async (target: AnyBuilder, aliasName: string): Promise<AnyBuilder> => {\n let next = target\n const tableName = aliasTables.get(aliasName)\n if (!tableName) return next\n if (orgScope && await this.columnExists(tableName, 'organization_id')) {\n next = this.applyOrganizationScope(next, `${aliasName}.organization_id`, orgScope)\n }\n if (opts.tenantId && await this.columnExists(tableName, 'tenant_id')) {\n next = next.where(`${aliasName}.tenant_id`, '=', opts.tenantId)\n }\n if (!opts.withDeleted && await this.columnExists(tableName, 'deleted_at')) {\n next = next.where(`${aliasName}.deleted_at`, 'is', null)\n }\n return next\n }\n\n const applyJoinFilterOpFn = (target: AnyBuilder, column: string, op: FilterOp, value?: unknown): AnyBuilder => {\n switch (op) {\n case 'eq':\n return value === null\n ? target.where(column, 'is', null)\n : target.where(column, '=', value as any)\n case 'ne':\n return value === null\n ? target.where(column, 'is not', null)\n : target.where(column, '!=', value as any)\n case 'gt': return target.where(column, '>', value as any)\n case 'gte': return target.where(column, '>=', value as any)\n case 'lt': return target.where(column, '<', value as any)\n case 'lte': return target.where(column, '<=', value as any)\n case 'in': return target.where(column, 'in', this.toArray(value))\n case 'nin': return target.where(column, 'not in', this.toArray(value))\n case 'like': return target.where(column, 'like', value as any)\n case 'ilike': return target.where(column, 'ilike', value as any)\n case 'exists': return value ? target.where(column, 'is not', null) : target.where(column, 'is', null)\n default: return target\n }\n }\n\n const applyJoinSearchFilterOp = async (\n target: AnyBuilder,\n filter: { column: string; op: FilterOp; value?: unknown },\n _qualified: string,\n join: ResolvedJoin,\n ): Promise<boolean> => {\n if (!searchEnabled || !join.entityId) return false\n if (!['like', 'ilike'].includes(filter.op)) return false\n if (typeof filter.value !== 'string' || filter.value.trim().length === 0) return false\n\n const searchAvailable = await this.searchAvailability().hasTokens(String(join.entityId), opts.tenantId ?? null, orgScope)\n if (!searchAvailable) return false\n\n const tokens = tokenizeText(String(filter.value), searchConfig)\n if (!tokens.hashes.length) return false\n\n return this.applySearchTokens(target, {\n entity: String(join.entityId),\n field: filter.column,\n hashes: tokens.hashes,\n recordIdColumn: `${join.alias}.id`,\n tenantId: opts.tenantId ?? null,\n organizationScope: orgScope,\n mintAlias: searchRuntime.mintAlias,\n })\n }\n\n const applyQueryShape = async (q: AnyBuilder): Promise<AnyBuilder> => {\n let next = applyBaseScope(q)\n next = applyEntityIndexesJoin(next)\n next = applyCustomFieldSourceJoins(next)\n next = applyCfFilters(next)\n next = applyRegularBaseFilters(next)\n next = applyOrGroupedBaseFilters(next)\n // applyJoinFilters is the shared helper that handles `joinFilters` (ALIAS:col -> value).\n next = await applyJoinFilters({\n db,\n baseTable,\n builder: next,\n joinMap,\n joinFilters,\n aliasTables,\n qualifyBase: (column) => qualify(column),\n applyAliasScope: async (target: any, alias: string) => applyAliasScopes(target as AnyBuilder, alias),\n applyFilterOp: (target, column, op, value) => applyJoinFilterOpFn(target as AnyBuilder, column, op, value),\n applyJoinFilterOp: async (target, filter, qualified, join) => {\n const applied = await applyJoinSearchFilterOp(target as AnyBuilder, filter, qualified, join)\n return { applied, builder: target }\n },\n columnExists: (tbl, column) => this.columnExists(tbl, column),\n })\n return next\n }\n\n const hasCustomFieldFilters = cfFilters.length > 0\n const canOptimizeCount = !hasCustomFieldFilters && !hasNonBaseSearchSource\n\n // Selection (for data query)\n const selectFieldSet = new Set<string>((opts.fields && opts.fields.length) ? opts.fields.map(String) : Array.from(columns.keys()))\n if (requiresPlaintextSort) {\n for (const field of encryptedSortFields) selectFieldSet.add(field)\n }\n if (opts.includeCustomFields === true) {\n const entityIds = Array.from(new Set(indexSources.map((src) => String(src.entityId))))\n try {\n const resolvedKeys = await this.resolveAvailableCustomFieldKeys(entityIds, opts.tenantId ?? null)\n resolvedKeys.forEach((key) => selectFieldSet.add(`cf:${key}`))\n if (this.isDebugVerbosity()) this.debug('query:cf:resolved-keys', { entity, keys: resolvedKeys })\n } catch (err) {\n logger.warn('Failed to resolve custom field keys', { entity, err })\n }\n } else if (Array.isArray(opts.includeCustomFields)) {\n opts.includeCustomFields.map((key) => String(key)).forEach((key) => selectFieldSet.add(`cf:${key}`))\n }\n const selectFields = Array.from(selectFieldSet)\n\n const applySelection = (q: AnyBuilder, fieldsOverride?: string[]): AnyBuilder => {\n let next = q\n const fields = fieldsOverride ?? selectFields\n for (const field of fields) {\n const fieldName = String(field)\n if (fieldName.startsWith('cf:')) {\n const alias = this.sanitize(fieldName)\n const jsonExpr = this.buildCfJsonExprSql(fieldName, indexSources)\n const exprRaw = jsonExpr ?? sql`NULL::jsonb`\n next = next.select(exprRaw.as(alias))\n } else if (columns.has(fieldName)) {\n next = next.select(`${qualify(fieldName)} as ${fieldName}`)\n }\n }\n return next\n }\n\n const applySort = (q: AnyBuilder): AnyBuilder => {\n let next = q\n if (requiresPlaintextSort) return next\n for (const s of resolvedSorts) {\n const fieldName = String(s.field)\n if (fieldName.startsWith('cf:')) {\n const textExpr = this.buildCfTextExprSql(fieldName, indexSources)\n if (textExpr) {\n const direction = sql.raw(coerceSortDirection(s.dir))\n next = next.orderBy(sql`${textExpr} ${direction}`)\n }\n } else {\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) continue\n next = next.orderBy(qualify(baseField), s.dir ?? SortDir.Asc)\n }\n }\n return next\n }\n\n const page = opts.page?.page ?? 1\n const pageSize = opts.page?.pageSize ?? 20\n const sqlDebugEnabled = this.isSqlDebugEnabled()\n\n let total: number\n\n if (canOptimizeCount) {\n // Optimized count: apply only base-scope + regular filters + or-group filters (no index joins).\n const optimizedRoot = db.selectFrom(`${baseTable} as b` as any)\n let countCore = applyBaseScope(optimizedRoot)\n countCore = applyRegularBaseFilters(countCore)\n countCore = applyOrGroupedBaseFilters(countCore)\n // joinFilters still need to be re-applied in the optimized path\n countCore = await applyJoinFilters({\n db,\n baseTable,\n builder: countCore,\n joinMap,\n joinFilters,\n aliasTables,\n qualifyBase: (column) => qualify(column),\n applyAliasScope: async (target: any, alias: string) => applyAliasScopes(target as AnyBuilder, alias),\n applyFilterOp: (target, column, op, value) => applyJoinFilterOpFn(target as AnyBuilder, column, op, value),\n applyJoinFilterOp: async (target, filter, qualified, join) => {\n const applied = await applyJoinSearchFilterOp(target as AnyBuilder, filter, qualified, join)\n return { applied, builder: target }\n },\n columnExists: (tbl, column) => this.columnExists(tbl, column),\n })\n const sub = countCore.select(sql.ref(qualify('id')).as('id')).groupBy(qualify('id')).as('sq')\n const countQuery = db.selectFrom(sub as any).select(sql<string>`count(*)`.as('count'))\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = countQuery.compile()\n this.debug('query:sql:count', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const countRow = await this.captureSqlTiming(\n 'query:sql:count', entity,\n () => countQuery.executeTakeFirst(),\n { optimized: true }, profiler,\n )\n total = this.parseCount(countRow)\n } else {\n const countRoot = db.selectFrom(`${baseTable} as b` as any)\n const countBuilder = (await applyQueryShape(countRoot))\n .select(sql<string>`count(distinct ${sql.ref(qualify('id'))})`.as('count'))\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = countBuilder.compile()\n this.debug('query:sql:count', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const countRow = await this.captureSqlTiming(\n 'query:sql:count', entity,\n () => countBuilder.executeTakeFirst(),\n { optimized: false }, profiler,\n )\n total = this.parseCount(countRow)\n }\n\n const dekKeyCache = new Map<string | null, string | null>()\n\n const decryptRow = async (item: Record<string, unknown>): Promise<Record<string, unknown>> => {\n let next = item\n if (encSvc?.decryptEntityPayload) {\n const decrypt = encSvc.decryptEntityPayload.bind(encSvc) as (\n entityId: EntityId, payload: Record<string, unknown>, tenantId: string | null, organizationId: string | null,\n ) => Promise<Record<string, unknown>>\n try {\n const decrypted = await decrypt(\n entity, next,\n (next?.tenant_id ?? next?.tenantId ?? opts.tenantId ?? null) as string | null,\n (next?.organization_id ?? next?.organizationId ?? fallbackOrgId ?? null) as string | null,\n )\n next = { ...next, ...decrypted }\n } catch (err) {\n logger.error('Error decrypting entity payload', { err })\n }\n }\n if (encSvc) {\n try {\n next = await decryptIndexDocCustomFields(\n next,\n {\n tenantId: (next?.tenant_id ?? next?.tenantId ?? opts.tenantId ?? null) as string | null,\n organizationId: (next?.organization_id ?? next?.organizationId ?? null) as string | null,\n },\n encSvc as any, dekKeyCache,\n )\n } catch { /* keep next as-is */ }\n }\n return next\n }\n\n let items: Record<string, unknown>[]\n let encryptedSortRowCapWarning: EncryptedSortRowCapWarning | undefined\n\n if (requiresPlaintextSort) {\n // Phase 1: slim id+sort-columns candidate scan, bounded-concurrency decrypt,\n // in-memory sort over the full candidate set, then slice to the page's ids.\n const cap = resolveEncryptedSortMaxRows()\n const phase1Root = db.selectFrom(`${baseTable} as b` as any)\n let phase1 = await applyQueryShape(phase1Root)\n const scopeFieldNames = [\n hasTenantColumn ? 'tenant_id' : null,\n hasOrganizationColumn ? 'organization_id' : null,\n ].filter((field): field is string => field !== null)\n const sortFieldNames = Array.from(new Set(['id', ...scopeFieldNames, ...resolvedSorts.map((s) => String(s.field))]))\n phase1 = applySelection(phase1, sortFieldNames)\n if (cap !== null) {\n phase1 = phase1.limit(cap).orderBy(qualify('id'), 'asc' as any)\n }\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = phase1.compile()\n this.debug('query:sql:data:phase1', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const candidateRows = await this.captureSqlTiming(\n 'query:sql:data:phase1', entity,\n () => phase1.execute(),\n { phase: 1 }, profiler,\n ) as Record<string, unknown>[]\n const decryptedCandidates = await mapWithConcurrency(candidateRows, DECRYPT_CONCURRENCY, decryptRow)\n const orderedCandidates = sortRowsInMemory(decryptedCandidates, resolvedSorts)\n const pageIds = orderedCandidates\n .slice((page - 1) * pageSize, page * pageSize)\n .map((row) => row.id)\n\n if (cap !== null && total > cap) {\n encryptedSortRowCapWarning = {\n entity,\n sortFields: resolvedSorts.map((s) => String(s.field)),\n maxRows: cap,\n totalMatched: total,\n }\n }\n\n // Phase 2: fetch + decrypt full rows for just the page's ids, then reassemble\n // in phase-1's order (SQL `WHERE id IN (...)` order is unspecified \u2014 never\n // trust it for ordering).\n if (pageIds.length === 0) {\n items = []\n } else {\n const phase2Root = db.selectFrom(`${baseTable} as b` as any)\n let phase2 = await applyQueryShape(phase2Root)\n phase2 = applySelection(phase2)\n phase2 = phase2.where(qualify('id'), 'in', pageIds)\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = phase2.compile()\n this.debug('query:sql:data:phase2', { entity, sql: compiled.sql, bindings: compiled.parameters })\n }\n const pageRowsRaw = await this.captureSqlTiming(\n 'query:sql:data:phase2', entity,\n () => phase2.execute(),\n { phase: 2 }, profiler,\n ) as Record<string, unknown>[]\n const decryptedPageRows = await mapWithConcurrency(pageRowsRaw, DECRYPT_CONCURRENCY, decryptRow)\n const byId = new Map(decryptedPageRows.map((row) => [String(row.id), row]))\n items = pageIds\n .map((id) => byId.get(String(id)))\n .filter((row): row is Record<string, unknown> => row != null)\n }\n } else {\n const dataRoot = db.selectFrom(`${baseTable} as b` as any)\n let dataBuilder = await applyQueryShape(dataRoot)\n dataBuilder = applySelection(dataBuilder)\n dataBuilder = applySort(dataBuilder)\n dataBuilder = dataBuilder.limit(pageSize).offset((page - 1) * pageSize)\n\n if (debugEnabled && sqlDebugEnabled) {\n const compiled = dataBuilder.compile()\n this.debug('query:sql:data', { entity, sql: compiled.sql, bindings: compiled.parameters, page, pageSize })\n }\n const itemsRaw = await this.captureSqlTiming(\n 'query:sql:data', entity,\n () => dataBuilder.execute(),\n { page, pageSize }, profiler,\n ) as Record<string, unknown>[]\n items = await mapWithConcurrency(itemsRaw, DECRYPT_CONCURRENCY, decryptRow)\n }\n if (debugEnabled) this.debug('query:complete', { entity, total, items: items.length })\n\n const typedItems = items as unknown as T[]\n let result: QueryResult<T> = { items: typedItems, page, pageSize, total }\n if (partialIndexWarning || encryptedSortRowCapWarning) {\n const meta: QueryResultMeta = {}\n if (partialIndexWarning) meta.partialIndexWarning = partialIndexWarning\n if (encryptedSortRowCapWarning) meta.encryptedSortRowCapWarning = encryptedSortRowCapWarning\n result.meta = meta\n }\n\n result = await applyAfterExtensions(result)\n finishProfile({\n result: 'ok', total, page, pageSize,\n itemCount: Array.isArray(items) ? items.length : undefined,\n partialIndexWarning: partialIndexWarning ? true : false,\n })\n return result\n } catch (err) {\n finishProfile({ result: 'error', error: err instanceof Error ? err.message : String(err) })\n throw err\n }\n }\n\n private prepareCustomFieldSources(\n sources: QueryCustomFieldSource[],\n ): PreparedCustomFieldSource[] {\n const prepared: PreparedCustomFieldSource[] = []\n sources.forEach((source, index) => {\n if (!source) return\n const joinTable = source.table ?? resolveEntityTableName(this.em, source.entityId)\n const alias = source.alias ?? `cfs_${index}`\n if (!source.join) {\n throw new Error(`QueryEngine: customFieldSources entry for ${String(source.entityId)} requires a join configuration`)\n }\n prepared.push({\n alias,\n indexAlias: `ei_${alias}`,\n entityId: source.entityId,\n recordIdColumn: source.recordIdColumn ?? 'id',\n organizationField: source.organizationField,\n tenantField: source.tenantField,\n table: joinTable,\n })\n })\n return prepared\n }\n\n private async isCustomEntity(entity: string): Promise<boolean> {\n const cached = this.customEntityCache.get(entity)\n if (cached !== undefined) return cached\n let result = false\n try {\n if (isOrmBackedSystemEntityId(this.em, entity)) {\n // An id backed by a registered ORM table is never doc-storage-backed. Classify it\n // as its base table BEFORE probing `custom_entities`, so neither a stray\n // `custom_entities_storage` row nor an active `custom_entities` row (e.g. a\n // presentation-metadata overlay for a system entity) can hijack every list/detail\n // read for the whole entity type away from its base table (#2939). This mirrors the\n // ORM-backed-first ordering already used by the records API (`classifyRecordsEntity`)\n // and the doc-storage write guard (`assertCustomEntityStorageEntityId`); without it\n // the read classifier alone trusted an active registration row over ORM-table\n // resolution. Surfaces that intentionally read doc records for a dual-declared id\n // pass `forceCustomEntityStorage` in QueryOptions instead.\n result = false\n } else {\n const db = this.getDb() as any\n const row = await db\n .selectFrom('custom_entities')\n .select('id')\n .where('entity_id', '=', entity)\n .where('is_active', '=', true)\n .executeTakeFirst()\n if (row) {\n result = true\n } else if (resolveRegisteredEntityTableName(this.em, entity) !== null) {\n // A non-registry id whose entity segment collides with an ORM class name (e.g.\n // `user:todo` vs the example module's `Todo`) resolves to a table but is NOT an\n // ORM-backed system entity, so it is not short-circuited above. Stray\n // `custom_entities_storage` rows for such an id must not hijack reads either.\n result = false\n } else {\n // Read/write symmetry. Records written through the entities data engine\n // (`de.createCustomEntityRecord`) always land in `custom_entities_storage`,\n // even for module-declared custom entities whose id is also a frozen system\n // id \u2014 those are NEVER registered in `custom_entities` (install treats a\n // system id as non-registrable). Without this fallback the query routes to\n // the empty ORM/index path and those records are write-only (created with\n // 200 but unreadable on the edit form).\n result = await this.hasCustomEntityStorageRows(entity)\n }\n }\n } catch {\n result = false\n }\n this.customEntityCache.set(entity, result)\n return result\n }\n\n private async hasCustomEntityStorageRows(entity: string): Promise<boolean> {\n try {\n const db = this.getDb() as any\n const row = await db\n .selectFrom('custom_entities_storage')\n .select(sql<number>`1`.as('one'))\n .where('entity_type', '=', entity)\n .limit(1)\n .executeTakeFirst()\n return !!row\n } catch {\n return false\n }\n }\n\n /**\n * Adds a WHERE EXISTS / OR WHERE EXISTS subquery that matches\n * `search_tokens` for the supplied (entity, field) against the\n * provided record id column.\n *\n * Returns true when the sub-query was applied (i.e. tokens were\n * non-empty). Caller is responsible for the calling context\n * (direct where vs. inside `eb.or([...])`).\n */\n private applySearchTokens(\n q: AnyBuilder,\n opts: {\n entity: string\n field: string\n hashes: string[]\n recordIdColumn: string\n tenantId?: string | null\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n combineWith?: 'and' | 'or'\n mintAlias: () => string\n }\n ): boolean {\n if (!opts.hashes.length) {\n this.logSearchDebug('search:skip-no-hashes', {\n entity: opts.entity, field: opts.field,\n tenantId: opts.tenantId ?? null, organizationScope: opts.organizationScope,\n })\n return false\n }\n const alias = opts.mintAlias()\n this.logSearchDebug('search:apply-search-tokens', {\n entity: opts.entity, field: opts.field, alias,\n tokenCount: opts.hashes.length,\n tenantId: opts.tenantId ?? null,\n organizationScope: opts.organizationScope,\n combineWith: opts.combineWith ?? 'and',\n })\n\n const engine = this\n const buildSub = (eb: any) => {\n let sub = eb\n .selectFrom(`search_tokens as ${alias}`)\n .select(sql<number>`1`.as('one'))\n .where(`${alias}.entity_type`, '=', opts.entity)\n .where(`${alias}.field`, '=', opts.field)\n .where(sql<boolean>`${sql.ref(`${alias}.entity_id`)} = ${sql.ref(opts.recordIdColumn)}::text`)\n .where(`${alias}.token_hash`, 'in', opts.hashes)\n .groupBy([`${alias}.entity_id`, `${alias}.field`])\n .having(sql<boolean>`count(distinct ${sql.ref(`${alias}.token_hash`)}) >= ${opts.hashes.length}`)\n if (opts.tenantId !== undefined) {\n sub = sub.where(sql<boolean>`${sql.ref(`${alias}.tenant_id`)} is not distinct from ${opts.tenantId ?? null}`)\n }\n if (opts.organizationScope) {\n sub = engine.applyOrganizationScope(sub, `${alias}.organization_id`, opts.organizationScope)\n }\n return sub\n }\n\n if (opts.combineWith === 'or') {\n // When called inside an .or([...]) array the caller supplied `eb`.\n // `q` is the ExpressionBuilder callable (eb) itself in that case.\n // We return the expression node rather than mutating q.\n ;(q as any).__pendingOrExists = buildSub(q)\n return true\n }\n\n // Default: append WHERE EXISTS (...) to the outer builder.\n ;(q as any).__applied = true\n const built = buildSub(q)\n // If q is a Kysely builder (has .where), use eb => eb.exists(sub)\n if (typeof q.where === 'function') {\n ;(q as any) = q.where((eb: any) => eb.exists(built))\n }\n return true\n }\n\n /** SQL fragment for `cf:<key>` (or legacy bare key) as JSON across a single alias. */\n private jsonbSqlAlias(alias: string, key: string): RawBuilder<unknown> {\n if (key.startsWith('cf:')) {\n const bare = key.slice(3)\n return sql`coalesce(${sql.ref(alias + '.doc')} -> ${key}, ${sql.ref(alias + '.doc')} -> ${bare})`\n }\n return sql`${sql.ref(alias + '.doc')} -> ${key}`\n }\n\n /** SQL fragment for `cf:<key>` (or legacy bare key) as text across a single alias. */\n private cfTextExprAlias(alias: string, key: string): RawBuilder<string | null> {\n if (key.startsWith('cf:')) {\n const bare = key.slice(3)\n return sql<string | null>`coalesce((${sql.ref(alias + '.doc')} ->> ${key}), (${sql.ref(alias + '.doc')} ->> ${bare}))`\n }\n return sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n }\n\n /** Build JSON/text SQL expressions across multiple index alias sources (coalesce over them). */\n private buildCfJsonExprSql(key: string, sources: IndexDocSource[]): RawBuilder<unknown> | null {\n if (!sources.length) return null\n const parts = sources.map((src) => this.jsonbSqlAlias(src.alias, key))\n if (parts.length === 1) return parts[0]\n return sql`coalesce(${sql.join(parts, sql`, `)})`\n }\n\n private buildCfTextExprSql(key: string, sources: IndexDocSource[]): RawBuilder<string | null> | null {\n if (!sources.length) return null\n const parts = sources.map((src) => this.cfTextExprAlias(src.alias, key))\n if (parts.length === 1) return parts[0]\n return sql<string | null>`coalesce(${sql.join(parts, sql`, `)})`\n }\n\n /**\n * Build a custom-field predicate as a standalone expression.\n *\n * Returning an expression rather than mutating a builder is what lets OR-grouped\n * cf leaves be combined with the base-column ones inside a single `WHERE`\n * (#5039). `null` means \"no predicate\" \u2014 an empty search-token set or an\n * unsupported operator \u2014 and callers must treat that as the leaf being absent.\n */\n private buildCfFilterExpression(\n eb: any,\n key: string,\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime\n ): any | null {\n if (!sources.length) return null\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (!hashes.length) {\n this.logSearchDebug('search:cf-skip-empty-hashes', {\n entity: sources.map((src) => src.entityId), field: key, value,\n })\n return null\n }\n const expression = this.buildMultiSourceSearchExists(eb, sources, key, hashes, search)\n this.logSearchDebug('search:cf-filter-across', {\n entity: sources.map((src) => src.entityId),\n field: key, tokens: tokens.tokens, hashes, applied: expression !== null,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return expression\n }\n\n const textExpr = this.buildCfTextExprSql(key, sources)\n const jsonExpr = this.buildCfJsonExprSql(key, sources)\n if (!textExpr || !jsonExpr) return null\n\n const arrContains = (val: unknown) => sql<boolean>`${jsonExpr} @> ${JSON.stringify([val])}::jsonb`\n\n switch (op) {\n case 'eq':\n // An unset custom field has no array element to contain, so the\n // arrContains branch cannot match it \u2014 compare the text value only.\n return value === null\n ? sql<boolean>`${textExpr} is null`\n : eb.or([\n sql<boolean>`${textExpr} = ${value}`,\n arrContains(value),\n ])\n case 'ne':\n return value === null\n ? sql<boolean>`${textExpr} is not null`\n : sql<boolean>`${textExpr} <> ${value}`\n case 'in': {\n const values = this.toArray(value)\n return eb.or(\n values.flatMap((val) => [\n sql<boolean>`${textExpr} = ${val}`,\n arrContains(val),\n ])\n )\n }\n case 'nin': {\n const values = this.toArray(value)\n return sql<boolean>`${textExpr} not in (${sql.join(values.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'like':\n return sql<boolean>`${textExpr} like ${value}`\n case 'ilike':\n return sql<boolean>`${textExpr} ilike ${value}`\n case 'exists':\n return value\n ? sql<boolean>`${textExpr} is not null`\n : sql<boolean>`${textExpr} is null`\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return sql<boolean>`${textExpr} ${operator} ${value}`\n }\n default:\n return null\n }\n }\n\n /**\n * Whether `buildCfFilterExpression` will produce a predicate for this leaf.\n *\n * Decidable without an ExpressionBuilder, which lets callers skip the `.where()`\n * entirely (rather than emitting a tautology) and lets the OR-group builder drop\n * leaves before it has to decide whether a disjunct survives.\n */\n private cfFilterHasPredicate(\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime,\n ): boolean {\n if (!sources.length) return false\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n return tokenizeText(String(value), search.config).hashes.length > 0\n }\n return CF_FILTER_SUPPORTED_OPS.has(op)\n }\n\n private applyCfFilterAcrossSources(\n builder: AnyBuilder,\n key: string,\n op: FilterOp,\n value: unknown,\n sources: IndexDocSource[],\n search?: SearchRuntime\n ): AnyBuilder {\n if (!this.cfFilterHasPredicate(op, value, sources, search)) {\n // Preserve the pre-existing behaviour of dropping a leaf we cannot compile.\n if (sources.length && (op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n this.logSearchDebug('search:cf-skip-empty-hashes', {\n entity: sources.map((src) => src.entityId), field: key, value,\n })\n }\n return builder\n }\n return builder.where((eb: any) => this.buildCfFilterExpression(eb, key, op, value, sources, search))\n }\n\n /** Build a search-token EXISTS predicate across multiple sources (OR-joined). */\n private buildMultiSourceSearchExists(\n eb: any,\n sources: IndexDocSource[],\n key: string,\n hashes: string[],\n search: SearchRuntime,\n ): any | null {\n if (!sources.length || !hashes.length) return null\n return eb.or(\n sources.map((source) =>\n eb.exists(this.buildSearchTokensSub(eb, {\n entity: String(source.entityId),\n field: key, hashes,\n recordIdColumn: `${source.alias}.entity_id`,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n }))\n )\n )\n }\n\n /** Construct a search-token EXISTS subquery using the given ExpressionBuilder. */\n private buildSearchTokensSub(\n eb: any,\n opts: {\n entity: string\n field: string\n hashes: string[]\n recordIdColumn: string\n tenantId?: string | null\n organizationScope?: { ids: string[]; includeNull: boolean } | null\n mintAlias: () => string\n }\n ): any {\n const alias = opts.mintAlias()\n let sub = eb\n .selectFrom(`search_tokens as ${alias}`)\n .select(sql<number>`1`.as('one'))\n .where(`${alias}.entity_type`, '=', opts.entity)\n .where(`${alias}.field`, '=', opts.field)\n .where(sql<boolean>`${sql.ref(`${alias}.entity_id`)} = ${sql.ref(opts.recordIdColumn)}::text`)\n .where(`${alias}.token_hash`, 'in', opts.hashes)\n .groupBy([`${alias}.entity_id`, `${alias}.field`])\n .having(sql<boolean>`count(distinct ${sql.ref(`${alias}.token_hash`)}) >= ${opts.hashes.length}`)\n if (opts.tenantId !== undefined) {\n sub = sub.where(sql<boolean>`${sql.ref(`${alias}.tenant_id`)} is not distinct from ${opts.tenantId ?? null}`)\n }\n if (opts.organizationScope) {\n sub = this.applyOrganizationScope(sub, `${alias}.organization_id`, opts.organizationScope)\n }\n return sub\n }\n\n private applyCfFilterFromAlias(\n q: AnyBuilder,\n alias: string,\n entityType: string,\n key: string,\n op: FilterOp,\n value: unknown,\n search?: SearchRuntime\n ): AnyBuilder {\n const textExpr = this.cfTextExprAlias(alias, key)\n const arrExpr = sql<unknown>`(${sql.ref(alias + '.doc')} -> ${key})`\n const arrContains = (val: unknown) => sql<boolean>`${arrExpr} @> ${JSON.stringify([val])}::jsonb`\n\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const applied = q.where((eb: any) => eb.exists(this.buildSearchTokensSub(eb, {\n entity: entityType, field: key, hashes,\n recordIdColumn: `${alias}.entity_id`,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n this.logSearchDebug('search:cf-filter', {\n entity: entityType, field: key, tokens: tokens.tokens, hashes, applied: true,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return applied\n } else {\n this.logSearchDebug('search:cf-skip-empty-hashes', { entity: entityType, field: key, value })\n }\n return q\n }\n switch (op) {\n case 'eq':\n // An unset custom field has no array element to contain, so the\n // arrContains branch cannot match it \u2014 compare the text value only.\n return value === null\n ? q.where(sql<boolean>`${textExpr} is null`)\n : q.where((eb: any) => eb.or([\n sql<boolean>`${textExpr} = ${value}`,\n arrContains(value),\n ]))\n case 'ne':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} <> ${value}`)\n case 'in': {\n const vals = this.toArray(value)\n return q.where((eb: any) => eb.or(\n vals.flatMap((val) => [\n sql<boolean>`${textExpr} = ${val}`,\n arrContains(val),\n ])\n ))\n }\n case 'nin': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'like':\n return q.where(sql<boolean>`${textExpr} like ${value}`)\n case 'ilike':\n return q.where(sql<boolean>`${textExpr} ilike ${value}`)\n case 'exists':\n return value\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} is null`)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return q.where(sql<boolean>`${textExpr} ${operator} ${value}`)\n }\n default:\n return q\n }\n }\n\n private applyIndexDocFilterFromAlias(\n q: AnyBuilder,\n alias: string,\n entityType: string,\n key: string,\n op: FilterOp,\n value: unknown,\n recordIdColumn: string,\n search?: SearchRuntime,\n ): AnyBuilder {\n const textExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n if ((op === 'like' || op === 'ilike') && search?.enabled && typeof value === 'string') {\n const tokens = tokenizeText(String(value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const applied = q.where((eb: any) => eb.exists(this.buildSearchTokensSub(eb, {\n entity: entityType, field: key, hashes, recordIdColumn,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n this.logSearchDebug('search:index-doc-filter', {\n entity: entityType, field: key, tokens: tokens.tokens, hashes, applied: true,\n tenantId: search.tenantId ?? null, organizationScope: search.organizationScope,\n })\n return applied\n } else {\n this.logSearchDebug('search:index-doc-skip-empty-hashes', { entity: entityType, field: key, value })\n }\n return q\n }\n switch (op) {\n case 'eq':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is null`)\n : q.where(sql<boolean>`${textExpr} = ${value}`)\n case 'ne':\n return value === null\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} <> ${value}`)\n case 'in': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'nin': {\n const vals = this.toArray(value)\n return q.where(sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`)\n }\n case 'like':\n return q.where(sql<boolean>`${textExpr} like ${value}`)\n case 'ilike':\n return q.where(sql<boolean>`${textExpr} ilike ${value}`)\n case 'exists':\n return value\n ? q.where(sql<boolean>`${textExpr} is not null`)\n : q.where(sql<boolean>`${textExpr} is null`)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return q.where(sql<boolean>`${textExpr} ${operator} ${value}`)\n }\n default:\n return q\n }\n }\n\n /**\n * Build a single OR-group base filter expression as a Kysely predicate\n * (no side effects on the outer builder).\n */\n private buildBaseFilterExpression(\n eb: any,\n filter: BaseFilter,\n resolveBaseColumn: (field: string) => string | null,\n qualify: (col: string) => string,\n entity: EntityId,\n searchRuntime: SearchRuntime,\n ): any {\n const fieldName = String(filter.field)\n const baseField = resolveBaseColumn(fieldName)\n if (!baseField) {\n // Doc-based filter via `ei` alias \u2014 returned as EXISTS where possible\n return this.buildIndexDocFilterExpression(eb, 'ei', entity, fieldName, filter.op, filter.value, 'b.id', searchRuntime)\n }\n // For like/ilike with active search-tokens, route through hashed-token EXISTS subquery\n // so encrypted-at-rest columns can still be searched.\n if (\n (filter.op === 'like' || filter.op === 'ilike') &&\n searchRuntime?.enabled &&\n typeof filter.value === 'string'\n ) {\n const tokens = tokenizeText(String(filter.value), searchRuntime.config)\n if (tokens.hashes.length) {\n const sources: SearchTokenSource[] = (searchRuntime.searchSources && searchRuntime.searchSources.length\n ? searchRuntime.searchSources\n : [{ entity: String(entity), recordIdColumn: 'b.id' }]\n ).filter((src) => src.recordIdColumn && src.entity)\n if (sources.length) {\n return eb.or(\n sources.map((src) =>\n eb.exists(this.buildSearchTokensSub(eb, {\n entity: src.entity,\n field: fieldName,\n hashes: tokens.hashes,\n recordIdColumn: src.recordIdColumn,\n tenantId: searchRuntime.tenantId ?? null,\n organizationScope: searchRuntime.organizationScope ?? null,\n mintAlias: searchRuntime.mintAlias,\n })),\n ),\n )\n }\n }\n // Tokenizer produced no hashes (e.g. value too short). Match the regular-base-filter\n // path's behavior of skipping the predicate (no filter), which is preferable to\n // silently turning into a plain `ilike` against an encrypted column.\n return sql<boolean>`true`\n }\n return this.buildColumnFilterExpression(eb, qualify(baseField), filter.op, filter.value)\n }\n\n private buildColumnFilterExpression(\n eb: any,\n column: string,\n op: FilterOp,\n value: unknown,\n ): any {\n switch (op) {\n case 'eq': return value === null ? eb(column, 'is', null) : eb(column, '=', value)\n case 'ne': return value === null ? eb(column, 'is not', null) : eb(column, '!=', value)\n case 'gt': return eb(column, '>', value)\n case 'gte': return eb(column, '>=', value)\n case 'lt': return eb(column, '<', value)\n case 'lte': return eb(column, '<=', value)\n case 'in': return eb(column, 'in', this.toArray(value))\n case 'nin': return eb(column, 'not in', this.toArray(value))\n case 'like': return eb(column, 'like', value)\n case 'ilike': return eb(column, 'ilike', value)\n case 'exists': return eb(column, value ? 'is not' : 'is', null)\n default: return sql<boolean>`true`\n }\n }\n\n private buildIndexDocFilterExpression(\n eb: any,\n alias: string,\n _entity: EntityId,\n key: string,\n op: FilterOp,\n value: unknown,\n _recordIdColumn: string,\n _search?: SearchRuntime,\n ): any {\n const textExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${key})`\n switch (op) {\n case 'eq': return value === null ? sql<boolean>`${textExpr} is null` : sql<boolean>`${textExpr} = ${value}`\n case 'ne': return value === null ? sql<boolean>`${textExpr} is not null` : sql<boolean>`${textExpr} <> ${value}`\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = sql.raw(op === 'gt' ? '>' : op === 'gte' ? '>=' : op === 'lt' ? '<' : '<=')\n return sql<boolean>`${textExpr} ${operator} ${value}`\n }\n case 'like': return sql<boolean>`${textExpr} like ${value}`\n case 'ilike': return sql<boolean>`${textExpr} ilike ${value}`\n case 'in': {\n const vals = this.toArray(value)\n return sql<boolean>`${textExpr} in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'nin': {\n const vals = this.toArray(value)\n return sql<boolean>`${textExpr} not in (${sql.join(vals.map((v) => sql`${v}`), sql`, `)})`\n }\n case 'exists':\n return value ? sql<boolean>`${textExpr} is not null` : sql<boolean>`${textExpr} is null`\n default:\n return sql<boolean>`true`\n }\n }\n\n private async queryCustomEntity<T = unknown>(entity: string, opts: QueryOptions = {}): Promise<QueryResult<T>> {\n const db = this.getDb() as any\n const alias = 'ce'\n\n const orgScope = this.resolveOrganizationScope(opts)\n if (!opts.tenantId) throw new Error('QueryEngine: tenantId is required')\n\n const normalizedFilters = normalizeFilters(opts.filters)\n const searchConfig = resolveSearchConfig()\n const searchEnabled = await this.searchAvailability().staticEnabled()\n // Same gate as `query()` (#4723): without a like/ilike filter the probe's answer is never read.\n const hasSearchTokens = searchEnabled && hasSearchFilter(normalizedFilters)\n ? await this.searchAvailability().hasTokens(entity, opts.tenantId ?? null, orgScope)\n : false\n const searchRuntime: SearchRuntime = {\n enabled: searchEnabled && hasSearchTokens,\n config: searchConfig,\n organizationScope: orgScope,\n tenantId: opts.tenantId ?? null,\n mintAlias: createSearchAliasMinter(),\n }\n\n const applyScope = (q: AnyBuilder): AnyBuilder => {\n let next = q\n .where(`${alias}.entity_type`, '=', entity)\n .where(`${alias}.tenant_id`, '=', opts.tenantId)\n if (orgScope) {\n next = this.applyOrganizationScope(next, `${alias}.organization_id`, orgScope)\n }\n if (!opts.withDeleted) next = next.where(`${alias}.deleted_at`, 'is', null)\n for (const filter of normalizedFilters) {\n if (filter.field.startsWith('cf:')) {\n next = this.applyCfFilterFromAlias(next, alias, entity, filter.field, filter.op, filter.value, searchRuntime)\n continue\n }\n const column = this.resolveCustomEntityColumn(alias, String(filter.field))\n if (column) {\n next = this.applyColumnFilter(next, column, filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: `${alias}.entity_id`,\n })\n continue\n }\n // Unknown field \u2192 filter on doc JSON text\n const docExpr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${String(filter.field)})`\n next = this.applyColumnFilter(next, docExpr, filter, {\n ...searchRuntime, entity, field: String(filter.field), recordIdColumn: `${alias}.entity_id`,\n })\n }\n return next\n }\n\n // Determine CFs and l10n keys to include\n const cfKeys = new Set<string>()\n for (const f of (opts.fields || [])) {\n if (typeof f === 'string' && f.startsWith('cf:')) cfKeys.add(f.slice(3))\n else if (typeof f === 'string' && f.startsWith('l10n:')) cfKeys.add(f)\n }\n for (const filter of normalizedFilters) {\n if (typeof filter.field === 'string' && filter.field.startsWith('cf:')) cfKeys.add(filter.field.slice(3))\n else if (typeof filter.field === 'string' && filter.field.startsWith('l10n:')) cfKeys.add(filter.field)\n }\n if (opts.includeCustomFields === true) {\n try {\n const rows = await db\n .selectFrom('custom_field_defs')\n .select('key')\n .where('entity_id', '=', entity)\n .where('is_active', '=', true)\n .where('tenant_id', '=', opts.tenantId)\n .execute() as Array<{ key: unknown }>\n for (const row of rows) {\n const key = row.key\n if (typeof key === 'string') cfKeys.add(key)\n else if (key != null) cfKeys.add(String(key))\n }\n } catch {\n // ignore\n }\n } else if (Array.isArray(opts.includeCustomFields)) {\n for (const k of opts.includeCustomFields) cfKeys.add(k)\n }\n\n const applySelection = (q: AnyBuilder): AnyBuilder => {\n let next = q\n const requested = (opts.fields && opts.fields.length) ? opts.fields : ['id']\n for (const field of requested) {\n const f = String(field)\n if (f.startsWith('cf:')) {\n const aliasName = this.sanitize(f)\n next = next.select(this.jsonbSqlAlias(alias, f).as(aliasName))\n } else if (f === 'id') {\n next = next.select(`${alias}.entity_id as id`)\n } else if (f === 'created_at' || f === 'updated_at' || f === 'deleted_at') {\n next = next.select(`${alias}.${f} as ${f}`)\n } else {\n const expr = sql<string | null>`(${sql.ref(alias + '.doc')} ->> ${f})`\n next = next.select(expr.as(f))\n }\n }\n // Ensure CF fields for sort / includeCustomFields are selected\n for (const key of cfKeys) {\n const aliasName = this.sanitize(`cf:${key}`)\n next = next.select(this.jsonbSqlAlias(alias, `cf:${key}`).as(aliasName))\n }\n return next\n }\n\n const applySort = (q: AnyBuilder): AnyBuilder => {\n let next = q\n for (const s of opts.sort || []) {\n if (s.field.startsWith('cf:')) {\n const key = s.field.slice(3)\n const aliasName = this.sanitize(`cf:${key}`)\n next = next.orderBy(aliasName, s.dir ?? SortDir.Asc)\n } else if (s.field === 'id') {\n next = next.orderBy(`${alias}.entity_id`, s.dir ?? SortDir.Asc)\n } else if (s.field === 'created_at' || s.field === 'updated_at' || s.field === 'deleted_at') {\n next = next.orderBy(`${alias}.${s.field}`, s.dir ?? SortDir.Asc)\n } else {\n const direction = sql.raw(coerceSortDirection(s.dir))\n next = next.orderBy(sql`(${sql.ref(alias + '.doc')} ->> ${s.field}) ${direction}`)\n }\n }\n return next\n }\n\n const page = opts.page?.page ?? 1\n const pageSize = opts.page?.pageSize ?? 20\n\n const root = db.selectFrom(`custom_entities_storage as ${alias}`)\n const countQuery = applyScope(root).select(sql<string>`count(distinct ${sql.ref(`${alias}.entity_id`)})`.as('count'))\n const countRow = await countQuery.executeTakeFirst()\n const total = this.parseCount(countRow)\n\n let dataQuery = applyScope(db.selectFrom(`custom_entities_storage as ${alias}`))\n dataQuery = applySelection(dataQuery)\n dataQuery = applySort(dataQuery)\n dataQuery = dataQuery.limit(pageSize).offset((page - 1) * pageSize)\n const items = await dataQuery.execute()\n return { items, page, pageSize, total }\n }\n\n private async tableExists(table: string): Promise<boolean> {\n const db = this.getDb() as any\n const exists = await db\n .selectFrom('information_schema.tables')\n .select(sql<number>`1`.as('one'))\n .where('table_name', '=', table)\n .executeTakeFirst()\n return !!exists\n }\n\n private async resolveAvailableCustomFieldKeys(entityIds: string[], tenantId: string | null): Promise<string[]> {\n if (!entityIds.length) return []\n const cacheKey = this.customFieldKeysCacheKey(entityIds, tenantId)\n const now = Date.now()\n const cached = this.customFieldKeysCache.get(cacheKey)\n if (cached && cached.expiresAt > now) return cached.value.slice()\n\n const db = this.getDb() as any\n const rows = await db\n .selectFrom('custom_field_defs')\n .select('key')\n .where('entity_id', 'in', entityIds)\n .where('is_active', '=', true)\n .where((eb: any) => eb.or([\n eb('tenant_id', '=', tenantId),\n eb('tenant_id', 'is', null),\n ]))\n .execute() as Array<{ key: unknown }>\n const keys = new Set<string>()\n for (const row of rows) {\n const key = row.key\n if (typeof key === 'string' && key.trim().length) keys.add(key.trim())\n else if (key != null) keys.add(String(key))\n }\n const result = Array.from(keys)\n if (this.customFieldKeysTtlMs > 0) {\n this.customFieldKeysCache.set(cacheKey, { expiresAt: now + this.customFieldKeysTtlMs, value: result })\n }\n return result.slice()\n }\n\n private async entityHasActiveCustomFields(entityId: string, tenantId: string | null): Promise<boolean> {\n try {\n const keys = await this.resolveAvailableCustomFieldKeys([entityId], tenantId)\n return keys.length > 0\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('query:cf:check-error', {\n entity: entityId, tenantId: tenantId ?? null,\n error: err instanceof Error ? err.message : err,\n })\n }\n return true\n }\n }\n\n private customFieldKeysCacheKey(entityIds: string[], tenantId: string | null): string {\n const sorted = entityIds.slice().sort((a, b) => a.localeCompare(b)).join(',')\n return `${tenantId ?? '__none__'}|${sorted}`\n }\n\n private resolveVectorService(): VectorIndexService | null {\n if (!this.vectorServiceResolver) return null\n try {\n return this.vectorServiceResolver() ?? null\n } catch {\n return null\n }\n }\n\n private resolveEntityLabel(entity: string): string {\n return entity\n }\n\n private async indexAnyRows(entity: string): Promise<boolean> {\n const db = this.getDb() as any\n const coverage = await db\n .selectFrom('entity_index_coverage')\n .select(sql<number>`1`.as('one'))\n .where('entity_type', '=', entity)\n .where('indexed_count', '>', 0)\n .executeTakeFirst()\n if (coverage) return true\n const exists = await db\n .selectFrom('entity_indexes')\n .select('entity_id')\n .where('entity_type', '=', entity)\n .executeTakeFirst()\n return !!exists\n }\n\n private async getStoredCoverageSnapshot(\n entity: string,\n tenantId: string | null,\n organizationId: string | null,\n withDeleted: boolean\n ): Promise<{ baseCount: number; indexedCount: number } | null> {\n try {\n const db = this.getDb()\n const scope = {\n entityType: entity, tenantId, organizationId, withDeleted,\n }\n const row = await readCoverageSnapshot(db as any, scope)\n if (row && this.isCoverageSnapshotFresh(row)) {\n return { baseCount: row.baseCount, indexedCount: row.indexedCount }\n }\n\n if (this.isCoverageOptimizationEnabled()) {\n this.scheduleCoverageRefresh(entity, tenantId, organizationId, withDeleted)\n if (!row) return null\n return { baseCount: row.baseCount, indexedCount: row.indexedCount }\n }\n\n await refreshCoverageSnapshot(this.em, scope)\n const refreshed = await readCoverageSnapshot(db as any, scope)\n if (!refreshed) return null\n return { baseCount: refreshed.baseCount, indexedCount: refreshed.indexedCount }\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('coverage:snapshot:read-error', {\n entity, tenantId, organizationId, withDeleted,\n error: err instanceof Error ? err.message : err,\n })\n }\n return null\n }\n }\n\n private isCoverageSnapshotFresh(\n row: Awaited<ReturnType<typeof readCoverageSnapshot>>\n ): boolean {\n if (this.coverageStatsTtlMs <= 0) return false\n if (!row) return false\n const refreshedAt = row.refreshed_at instanceof Date\n ? row.refreshed_at\n : row.refreshed_at\n ? new Date(row.refreshed_at)\n : null\n const refreshedAtMs = refreshedAt?.getTime()\n if (!refreshedAtMs || !Number.isFinite(refreshedAtMs)) return false\n return Date.now() - refreshedAtMs <= this.coverageStatsTtlMs\n }\n\n private scheduleAutoReindex(\n entity: string,\n opts: QueryOptions,\n stats?: { baseCount: number; indexedCount: number },\n organizationIdOverride?: string | null\n ) {\n if (!this.isAutoReindexEnabled()) return\n const bus = this.resolveEventBus()\n if (!bus) return\n const payload = {\n entityType: entity,\n tenantId: opts.tenantId ?? null,\n organizationId: organizationIdOverride ?? opts.organizationId ?? null,\n force: false,\n }\n const debounceMs = this.getAutoReindexDebounceMs()\n if (debounceMs > 0) {\n const key = [payload.entityType, payload.tenantId ?? '__tenant__', payload.organizationId ?? '__org__'].join('|')\n if (!markAutoReindexScheduled(key, debounceMs, Date.now())) return\n }\n const context = stats\n ? { entity, tenantId: payload.tenantId, organizationId: payload.organizationId, baseCount: stats.baseCount, indexedCount: stats.indexedCount }\n : { entity, tenantId: payload.tenantId, organizationId: payload.organizationId }\n\n void Promise.resolve().then(async () => {\n try {\n await bus.emitEvent('query_index.reindex', payload, { persistent: true })\n if (this.isDebugVerbosity()) this.debug('query:auto-reindex:scheduled', context)\n } catch (err) {\n logger.warn('Failed to schedule auto reindex', { ...context, err })\n }\n })\n }\n\n private scheduleCoverageRefresh(\n entity: string,\n tenantId: string | null | undefined,\n organizationId: string | null | undefined,\n withDeleted: boolean\n ): void {\n const bus = this.resolveEventBus()\n if (!bus) return\n const key = [entity, tenantId ?? '__tenant__', organizationId ?? '__org__', withDeleted ? '1' : '0'].join('|')\n if (this.pendingCoverageRefreshKeys.has(key)) return\n this.pendingCoverageRefreshKeys.add(key)\n void Promise.resolve()\n .then(async () => {\n try {\n await bus.emitEvent('query_index.coverage.refresh', {\n entityType: entity,\n tenantId: tenantId ?? null, organizationId: organizationId ?? null,\n withDeleted, delayMs: 0,\n })\n if (this.isDebugVerbosity()) {\n this.debug('coverage:refresh:scheduled', {\n entity, tenantId: tenantId ?? null, organizationId: organizationId ?? null, withDeleted,\n })\n }\n } catch (err) {\n if (this.isDebugVerbosity()) {\n this.debug('coverage:refresh:failed', {\n entity, tenantId: tenantId ?? null, organizationId: organizationId ?? null, withDeleted,\n error: err instanceof Error ? err.message : err,\n })\n }\n }\n })\n .finally(() => { this.pendingCoverageRefreshKeys.delete(key) })\n }\n\n private resolveEventBus(): Pick<EventBus, 'emitEvent'> | null {\n if (!this.eventBusResolver) return null\n try {\n const bus = this.eventBusResolver()\n return bus ?? null\n } catch {\n return null\n }\n }\n\n private isAutoReindexEnabled(): boolean {\n if (this.autoReindexEnabled != null) return this.autoReindexEnabled\n const raw = (process.env.SCHEDULE_AUTO_REINDEX ?? process.env.QUERY_INDEX_AUTO_REINDEX ?? '').trim().toLowerCase()\n if (!raw) { this.autoReindexEnabled = true; return true }\n const parsed = parseBooleanToken(raw)\n this.autoReindexEnabled = parsed === null ? true : parsed\n return this.autoReindexEnabled\n }\n\n private getAutoReindexDebounceMs(): number {\n if (this.autoReindexDebounceMs != null) return this.autoReindexDebounceMs\n this.autoReindexDebounceMs = parseNumberWithDefault(\n process.env.OM_QUERY_INDEX_AUTO_REINDEX_DEBOUNCE_MS,\n AUTO_REINDEX_DEBOUNCE_DEFAULT_MS,\n { integer: true, min: 0 },\n )\n return this.autoReindexDebounceMs\n }\n\n private isCoverageOptimizationEnabled(): boolean {\n if (this.coverageOptimizationEnabled != null) return this.coverageOptimizationEnabled\n const raw = (process.env.OPTIMIZE_INDEX_COVERAGE_STATS ?? '').trim().toLowerCase()\n if (!raw) { this.coverageOptimizationEnabled = false; return false }\n this.coverageOptimizationEnabled = parseBooleanToken(raw) === true\n return this.coverageOptimizationEnabled\n }\n\n private async columnExists(table: string, column: string): Promise<boolean> {\n const key = `${table}.${column}`\n if (this.columnCache.has(key)) {\n const cached = this.columnCache.get(key)\n if (cached === true) return true\n this.columnCache.delete(key)\n }\n const db = this.getDb() as any\n const exists = await db\n .selectFrom('information_schema.columns')\n .select(sql<number>`1`.as('one'))\n .where('table_name', '=', table)\n .where('column_name', '=', column)\n .executeTakeFirst()\n const present = !!exists\n if (present) this.columnCache.set(key, true)\n else this.columnCache.delete(key)\n return present\n }\n\n private async getBaseColumnsForEntity(entity: string): Promise<Map<string, string>> {\n const db = this.getDb() as any\n const table = resolveEntityTableName(this.em, entity)\n const rows = await db\n .selectFrom('information_schema.columns')\n .select(['column_name', 'data_type'])\n .where('table_name', '=', table)\n .execute() as Array<{ column_name: string; data_type: string }>\n const map = new Map<string, string>()\n for (const r of rows) map.set(r.column_name, r.data_type)\n return map\n }\n\n private resolveOrganizationScope(opts: QueryOptions): { ids: string[]; includeNull: boolean } | null {\n if (opts.organizationIds !== undefined) {\n const raw = (opts.organizationIds ?? []).map((id) => (typeof id === 'string' ? id.trim() : id))\n const includeNull = raw.some((id) => id == null || id === '')\n const ids = raw.filter((id): id is string => typeof id === 'string' && id.length > 0)\n const unique = Array.from(new Set(ids))\n return { ids: unique, includeNull }\n }\n if (typeof opts.organizationId === 'string' && opts.organizationId.trim().length > 0) {\n return { ids: [opts.organizationId], includeNull: false }\n }\n return null\n }\n\n private resolveCoverageSnapshotScope(\n opts: QueryOptions\n ): { tenantId: string | null; organizationId: string | null } | null {\n const tenantId = opts.tenantId ?? null\n const orgScope = this.resolveOrganizationScope(opts)\n if (!orgScope) return { tenantId, organizationId: null }\n if (orgScope.includeNull) {\n if (orgScope.ids.length === 0) return { tenantId, organizationId: null }\n return null\n }\n if (orgScope.ids.length === 1) return { tenantId, organizationId: orgScope.ids[0] }\n if (orgScope.ids.length === 0) return { tenantId, organizationId: null }\n return null\n }\n\n private applyOrganizationScope(\n q: AnyBuilder,\n column: string,\n scope: { ids: string[]; includeNull: boolean }\n ): AnyBuilder {\n if (scope.ids.length === 0 && !scope.includeNull) {\n return q.where(sql<boolean>`1 = 0`)\n }\n return q.where((eb: any) => {\n const parts: any[] = []\n if (scope.ids.length > 0) parts.push(eb(column, 'in', scope.ids))\n if (scope.includeNull) parts.push(eb(column, 'is', null))\n if (parts.length === 1) return parts[0]\n return eb.or(parts)\n })\n }\n\n private normalizeFilters(filters?: QueryOptions['filters']): NormalizedFilter[] {\n if (!filters) return []\n const normalizeField = (k: string) => k.startsWith('cf_') ? `cf:${k.slice(3)}` : k\n if (Array.isArray(filters)) {\n return (filters as Filter[]).map((filter) => ({\n field: normalizeField(String(filter.field)),\n op: filter.op, value: filter.value,\n }))\n }\n const out: NormalizedFilter[] = []\n const obj = filters as Record<string, unknown>\n const add = (field: string, op: FilterOp, value?: unknown) => out.push({ field, op, value })\n for (const [rawKey, rawVal] of Object.entries(obj)) {\n const field = normalizeField(rawKey)\n if (rawVal !== null && typeof rawVal === 'object' && !Array.isArray(rawVal)) {\n for (const [opKey, opVal] of Object.entries(rawVal as Record<string, unknown>)) {\n switch (opKey) {\n case '$eq': add(field, 'eq', opVal); break\n case '$ne': add(field, 'ne', opVal); break\n case '$gt': add(field, 'gt', opVal); break\n case '$gte': add(field, 'gte', opVal); break\n case '$lt': add(field, 'lt', opVal); break\n case '$lte': add(field, 'lte', opVal); break\n case '$in': add(field, 'in', opVal); break\n case '$nin': add(field, 'nin', opVal); break\n case '$like': add(field, 'like', opVal); break\n case '$ilike': add(field, 'ilike', opVal); break\n case '$exists': add(field, 'exists', opVal); break\n }\n }\n } else {\n add(field, 'eq', rawVal)\n }\n }\n return out\n }\n\n private sanitize(s: string): string {\n return s.replace(/[^a-zA-Z0-9_]/g, '_')\n }\n\n private toArray(value: unknown): readonly unknown[] {\n if (Array.isArray(value)) return value\n if (value === undefined) return []\n return [value]\n }\n\n private parseCount(row: unknown): number {\n if (row && typeof row === 'object' && 'count' in row) {\n const value = (row as { count: unknown }).count\n if (typeof value === 'number') return value\n if (typeof value === 'string') {\n const parsed = Number(value)\n return Number.isNaN(parsed) ? 0 : parsed\n }\n if (typeof value === 'bigint') return Number(value)\n }\n return 0\n }\n\n private logSearchDebug(event: string, payload: Record<string, unknown>) {\n if (!this.isDebugVerbosity()) return\n logger.debug('Search debug event', { event, payload })\n }\n\n private applyColumnFilter(\n q: AnyBuilder,\n column: string | RawBuilder<unknown>,\n filter: NormalizedFilter,\n search?: SearchRuntime & { entity: string; field: string; recordIdColumn?: string },\n ): AnyBuilder {\n if (\n (filter.op === 'like' || filter.op === 'ilike') &&\n search?.enabled &&\n typeof filter.value === 'string'\n ) {\n const tokens = tokenizeText(String(filter.value), search.config)\n const hashes = tokens.hashes\n if (hashes.length) {\n const sources: SearchTokenSource[] = (search.searchSources && search.searchSources.length\n ? search.searchSources\n : [{ entity: search.entity, recordIdColumn: search.recordIdColumn ?? '' }]\n ).filter((src) => src.recordIdColumn && src.entity)\n if (sources.length) {\n const engine = this\n q = q.where((eb: any) => eb.or(\n sources.map((src) =>\n eb.exists(engine.buildSearchTokensSub(eb, {\n entity: src.entity, field: search.field, hashes,\n recordIdColumn: src.recordIdColumn,\n tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope ?? null,\n mintAlias: search.mintAlias,\n })))\n ))\n this.logSearchDebug('search:filter', {\n entity: search.entity, field: search.field, tokens: tokens.tokens, hashes,\n applied: true, tenantId: search.tenantId ?? null,\n organizationScope: search.organizationScope,\n sources: sources.map((src) => ({ entity: src.entity, recordIdColumn: src.recordIdColumn })),\n })\n return q\n }\n } else {\n this.logSearchDebug('search:skip-empty-hashes', {\n entity: search.entity, field: search.field, value: filter.value,\n })\n }\n return q\n }\n const col: any = column\n switch (filter.op) {\n case 'eq':\n return filter.value === null\n ? q.where(col, 'is', null)\n : q.where(col, '=', filter.value as any)\n case 'ne':\n return filter.value === null\n ? q.where(col, 'is not', null)\n : q.where(col, '!=', filter.value as any)\n case 'gt':\n case 'gte':\n case 'lt':\n case 'lte': {\n const operator = filter.op === 'gt' ? '>' : filter.op === 'gte' ? '>=' : filter.op === 'lt' ? '<' : '<='\n return q.where(col, operator, filter.value as any)\n }\n case 'in':\n return q.where(col, 'in', this.toArray(filter.value))\n case 'nin':\n return q.where(col, 'not in', this.toArray(filter.value))\n case 'like':\n return q.where(col, 'like', filter.value as any)\n case 'ilike':\n return q.where(col, 'ilike', filter.value as any)\n case 'exists':\n return filter.value ? q.where(col, 'is not', null) : q.where(col, 'is', null)\n default:\n return q\n }\n }\n\n private resolveCustomEntityColumn(alias: string, field: string): string | null {\n if (field === 'id') return `${alias}.entity_id`\n if (field === 'organization_id' || field === 'organizationId') return `${alias}.organization_id`\n if (field === 'tenant_id' || field === 'tenantId') return `${alias}.tenant_id`\n if (field === 'created_at' || field === 'updated_at' || field === 'deleted_at') return `${alias}.${field}`\n return null\n }\n\n private isDebugVerbosity(): boolean {\n if (this.debugVerbosity != null) return this.debugVerbosity\n this.debugVerbosity = resolveDebugVerbosity()\n return this.debugVerbosity\n }\n\n private isSqlDebugEnabled(): boolean {\n if (this.sqlDebugEnabled != null) return this.sqlDebugEnabled\n this.sqlDebugEnabled = resolveBooleanEnv(['QUERY_ENGINE_DEBUG_SQL'], false)\n return this.sqlDebugEnabled\n }\n\n private isForcePartialIndexEnabled(): boolean {\n if (this.forcePartialIndexEnabled != null) return this.forcePartialIndexEnabled\n this.forcePartialIndexEnabled = resolveBooleanEnv(['FORCE_QUERY_INDEX_ON_PARTIAL_INDEXES'], false)\n return this.forcePartialIndexEnabled\n }\n\n private async resolveCoverageGap(\n entity: string,\n opts: QueryOptions,\n coverageScope?: { tenantId: string | null; organizationId: string | null } | null,\n _sourceTable?: string\n ): Promise<{ stats?: { baseCount: number; indexedCount: number }; scope: 'scoped' | 'global' } | null> {\n const scope = coverageScope ?? this.resolveCoverageSnapshotScope(opts)\n if (!scope) return null\n const tenantId = scope.tenantId\n const organizationId = scope.organizationId\n const withDeleted = !!opts.withDeleted\n\n const snapshot = await this.getStoredCoverageSnapshot(entity, tenantId, organizationId, withDeleted)\n if (!snapshot) {\n this.scheduleCoverageRefresh(entity, tenantId, organizationId, withDeleted)\n return { stats: undefined, scope: 'scoped' }\n }\n\n const baseCount = snapshot.baseCount\n const indexCount = snapshot.indexedCount\n const hasGap = baseCount > 0 && indexCount < baseCount\n if (hasGap || indexCount > baseCount) return { stats: snapshot, scope: 'scoped' }\n return null\n }\n\n // Backward-compatible hook for tests that mock coverage stats\n private async indexCoverageStats(\n entity: string,\n opts: QueryOptions,\n coverageScope?: { tenantId: string | null; organizationId: string | null } | null,\n ): Promise<{ baseCount: number; indexedCount: number } | null> {\n const gap = await this.resolveCoverageGap(entity, opts, coverageScope)\n return gap?.stats ?? null\n }\n\n private async captureSqlTiming<TResult>(\n label: string,\n entity: EntityId,\n execute: () => Promise<TResult> | TResult,\n extra?: Record<string, unknown>,\n profiler?: Profiler\n ): Promise<TResult> {\n const shouldDebug = this.isSqlDebugEnabled() && this.isDebugVerbosity()\n const shouldProfile = profiler?.enabled === true\n if (!shouldDebug && !shouldProfile) return Promise.resolve(execute())\n const startedAt = process.hrtime.bigint()\n try {\n return await Promise.resolve(execute())\n } finally {\n const elapsedMs = Number(process.hrtime.bigint() - startedAt) / 1_000_000\n const context: Record<string, unknown> = { entity, durationMs: Math.round(elapsedMs * 1000) / 1000 }\n if (extra) Object.assign(context, extra)\n if (shouldProfile) profiler!.record(label, context.durationMs as number, extra)\n if (shouldDebug) this.debug(`${label}:timing`, context)\n }\n }\n\n private debug(message: string, context?: Record<string, unknown>): void {\n if (!this.isDebugVerbosity()) return\n if (!this.isSqlDebugEnabled()) return\n if (context) logger.debug(message, context)\n else logger.debug(message)\n }\n}\n"],
|
|
5
|
+
"mappings": "AACA,SAAS,eAAe;AAGxB,SAA2B,wBAAwB,wCAAwC;AAC3F,SAAS,iCAAiC;AAC1C,SAAsB,WAA4B;AAElD,SAAS,sBAAsB,+BAA+B;AAC9D,SAAS,gBAAgB,4BAA2C;AAEpE,SAAS,mCAAmC;AAC5C,SAAS,mBAAmB,+BAA+B;AAC3D;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AACP,SAAS,2BAA8C;AACvD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AACP,SAAS,oBAAoB;AAC7B,SAAS,wBAAwB,6BAAyD;AAC1F,SAAS,oCAAoC;AAC7C,SAAS,4BAA4B,6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