@resolveio/server-lib 22.3.219 → 22.3.221
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/.nodemon.json +5 -0
- package/.vscode/settings.json +21 -0
- package/AGENTS.md +195 -0
- package/README.md +22 -0
- package/build_package.sh +5 -0
- package/compileDTS.pl +64 -0
- package/docs/ai-assistant-nightly-eval.md +65 -0
- package/docs/ai-assistant-preflight-checklist.md +23 -0
- package/docs/ai-assistant-report-builder-bridge-playbook.md +115 -0
- package/eslint-plugin-custom/index.js +7 -0
- package/eslint-plugin-custom/rules/no-filter-zero-index.js +44 -0
- package/eslint.config.js +103 -0
- package/gulpfile.js +216 -0
- package/methodAndPublicationListGenerator.py +375 -0
- package/mongodbensurers.js +2 -0
- package/mongostop.js +3 -0
- package/package.json +1 -1
- package/scripts/cleanup-bypassed-callmethod-logs.js +616 -0
- package/settings.development.json +25 -0
- package/settings.development.redacted.json +25 -0
- package/src/.env +12 -0
- package/src/ai/assistant-core-heuristics.ts +379 -0
- package/src/ai/resolveio-platform-intelligence-memory-corpus.ts +185 -0
- package/src/ai/resolveio-platform-intelligence-memory.ts +325 -0
- package/{ai/resolveio-platform-intelligence-types.d.ts → src/ai/resolveio-platform-intelligence-types.ts} +20 -15
- package/src/ai/resolveio-platform-intelligence.ts +462 -0
- package/src/client-server-app.ts +12 -0
- package/src/collections/ai-run.collection.ts +117 -0
- package/src/collections/ai-terminal-conversation.collection.ts +91 -0
- package/src/collections/ai-terminal-issue-report.collection.ts +99 -0
- package/src/collections/ai-terminal-message.collection.ts +77 -0
- package/src/collections/app-setting.collection.ts +104 -0
- package/src/collections/app-status.collection.ts +58 -0
- package/src/collections/communication-metric.collection.ts +84 -0
- package/src/collections/counter.collection.ts +56 -0
- package/src/collections/cron-job-history.collection.ts +94 -0
- package/src/collections/cron-job.collection.ts +92 -0
- package/src/collections/customer-notification.collection.ts +131 -0
- package/src/collections/customer-portal-password.collection.ts +76 -0
- package/src/collections/email-history.collection.ts +134 -0
- package/src/collections/email-verified.collection.ts +62 -0
- package/src/collections/file.collection.ts +74 -0
- package/src/collections/flag-update.collection.ts +57 -0
- package/src/collections/flag.collection.ts +57 -0
- package/src/collections/log-method-latency.collection.ts +77 -0
- package/src/collections/log-subscription.collection.ts +80 -0
- package/src/collections/log.collection.ts +93 -0
- package/src/collections/logged-in-users.collection.ts +67 -0
- package/src/collections/monitor-cpu.collection.ts +65 -0
- package/src/collections/monitor-function.collection.ts +74 -0
- package/src/collections/monitor-memory.collection.ts +77 -0
- package/src/collections/monitor-mongo.collection.ts +71 -0
- package/src/collections/notification.collection.ts +57 -0
- package/src/collections/openai-usage-ledger.collection.ts +131 -0
- package/src/collections/report-builder-dashboard-builder.collection.ts +109 -0
- package/src/collections/report-builder-library.collection.ts +89 -0
- package/src/collections/report-builder-report.collection.ts +184 -0
- package/src/collections/user-group.collection.ts +89 -0
- package/src/collections/user-guide.collection.ts +57 -0
- package/src/collections/user.collection.ts +181 -0
- package/src/cron/cron.ts +117 -0
- package/src/fixtures/cron-jobs.ts +95 -0
- package/src/fixtures/init.ts +35 -0
- package/src/http/auth.ts +818 -0
- package/src/http/health.ts +7 -0
- package/src/http/home.ts +90 -0
- package/src/http/slow-query-publication.ts +49 -0
- package/src/index.ts +1 -0
- package/src/managers/ai-assistant-codex-manager.manager.ts +1131 -0
- package/src/managers/ai-run-evidence.manager.ts +264 -0
- package/src/managers/communication-metric.manager.ts +82 -0
- package/src/managers/cron.manager.ts +333 -0
- package/src/managers/customer-notification-content.manager.ts +236 -0
- package/src/managers/diagnostic-manager-bootstrap.ts +165 -0
- package/src/managers/error-auto-fix.manager.ts +2767 -0
- package/src/managers/local-log.manager.ts +113 -0
- package/src/managers/method.manager.ts +1857 -0
- package/src/managers/mongo.manager.ts +4575 -0
- package/src/managers/monitor.manager.ts +507 -0
- package/src/managers/openai-usage-ledger.manager.ts +112 -0
- package/src/managers/slow-query-verifier.manager.ts +3590 -0
- package/src/managers/slow-query.manager.ts +519 -0
- package/src/managers/subscription.manager.ts +3128 -0
- package/src/managers/websocket.manager.ts +746 -0
- package/src/managers/worker-dispatcher.manager.ts +1360 -0
- package/src/managers/worker-server.manager.ts +536 -0
- package/src/methods/accounts.ts +532 -0
- package/src/methods/ai-terminal.ts +29070 -0
- package/src/methods/app-settings.ts +114 -0
- package/src/methods/aws.ts +649 -0
- package/src/methods/collections.ts +641 -0
- package/src/methods/counters.ts +69 -0
- package/src/methods/cron-jobs.ts +2614 -0
- package/src/methods/customer-notifications.ts +458 -0
- package/src/methods/diagnostics.ts +616 -0
- package/src/methods/flag-updates.ts +7 -0
- package/src/methods/flags.ts +7 -0
- package/src/methods/logs.ts +657 -0
- package/src/methods/mongo-explorer.ts +1880 -0
- package/src/methods/monitor.ts +540 -0
- package/src/methods/pdf.ts +1236 -0
- package/src/methods/publications.ts +129 -0
- package/src/methods/report-builder.ts +3300 -0
- package/src/methods/support.ts +335 -0
- package/src/models/ai-run.model.ts +27 -0
- package/src/models/ai-terminal-conversation.model.ts +19 -0
- package/src/models/ai-terminal-issue-report.model.ts +21 -0
- package/src/models/ai-terminal-message.model.ts +24 -0
- package/src/models/app-setting.model.ts +17 -0
- package/{models/app-status.model.d.ts → src/models/app-status.model.ts} +3 -2
- package/{models/billing-logged-in-users.model.d.ts → src/models/billing-logged-in-users.model.ts} +5 -4
- package/src/models/collection-document.model.ts +24 -0
- package/src/models/communication-metric.model.ts +23 -0
- package/{models/counter.model.d.ts → src/models/counter.model.ts} +4 -3
- package/src/models/cron-job-history.model.ts +16 -0
- package/src/models/cron-job.model.ts +15 -0
- package/src/models/customer-notification.model.ts +28 -0
- package/src/models/customer-portal-password.model.ts +12 -0
- package/src/models/dialog.model.ts +25 -0
- package/{models/email-history.model.js → src/models/email-history.model.ts} +36 -4
- package/{models/email-verified.model.d.ts → src/models/email-verified.model.ts} +6 -5
- package/{models/file.model.d.ts → src/models/file.model.ts} +8 -7
- package/{models/flag-update.model.d.ts → src/models/flag-update.model.ts} +4 -3
- package/{models/flag.model.d.ts → src/models/flag.model.ts} +4 -3
- package/src/models/log-method-latency.model.ts +11 -0
- package/{models/log-subscription.model.d.ts → src/models/log-subscription.model.ts} +11 -9
- package/src/models/log.model.ts +19 -0
- package/{models/logged-in-users.model.d.ts → src/models/logged-in-users.model.ts} +6 -5
- package/{models/method-response.model.d.ts → src/models/method-response.model.ts} +7 -6
- package/src/models/method.model.ts +25 -0
- package/{models/monitor-cpu.model.d.ts → src/models/monitor-cpu.model.ts} +9 -7
- package/src/models/monitor-function.model.ts +16 -0
- package/src/models/monitor-memory.model.ts +17 -0
- package/src/models/monitor-mongo.model.ts +15 -0
- package/{models/notification.model.d.ts → src/models/notification.model.ts} +6 -4
- package/src/models/openai-usage-ledger.model.ts +56 -0
- package/src/models/pagination.model.ts +35 -0
- package/src/models/permission.model.ts +14 -0
- package/src/models/report-builder-dashboard-builder.model.ts +29 -0
- package/src/models/report-builder-library.model.ts +20 -0
- package/src/models/report-builder-report.model.ts +136 -0
- package/src/models/report-builder.model.ts +68 -0
- package/src/models/select-data-label.model.ts +9 -0
- package/src/models/server-message.model.ts +31 -0
- package/src/models/slow-query-report.model.ts +23 -0
- package/src/models/subscription.model.ts +73 -0
- package/src/models/support-ticket.model.ts +104 -0
- package/src/models/user-group.model.ts +24 -0
- package/{models/user-guide.model.d.ts → src/models/user-guide.model.ts} +5 -4
- package/src/models/user.model.ts +96 -0
- package/src/private/images/ResolveIO.png +0 -0
- package/src/publications/ai-terminal.ts +73 -0
- package/src/publications/app-settings.ts +25 -0
- package/src/publications/app-status.ts +13 -0
- package/src/publications/cron-jobs.ts +40 -0
- package/src/publications/customer-notifications.ts +101 -0
- package/src/publications/files.ts +33 -0
- package/src/publications/flags-update.ts +19 -0
- package/src/publications/flags.ts +19 -0
- package/src/publications/logs.ts +163 -0
- package/src/publications/notifications.ts +13 -0
- package/src/publications/report-builder-dashboard-builders.ts +39 -0
- package/src/publications/report-builder-libraries.ts +41 -0
- package/src/publications/report-builder-reports.ts +47 -0
- package/src/publications/super-admin.ts +13 -0
- package/src/publications/user-groups.ts +12 -0
- package/src/publications/user-guides.ts +12 -0
- package/src/resolveio-server-app.ts +617 -0
- package/src/server-app.ts +3354 -0
- package/src/services/codex-client.ts +1231 -0
- package/src/services/openai-client.ts +265 -0
- package/src/types/error-report.ts +26 -0
- package/src/types/js-tiktoken.d.ts +11 -0
- package/src/types/slow-query-report.ts +28 -0
- package/src/util/ai-qa-policy.ts +925 -0
- package/src/util/ai-run-evidence-adapters.ts +8347 -0
- package/src/util/ai-run-evidence-dashboard.ts +323 -0
- package/src/util/ai-run-evidence-eval.ts +1057 -0
- package/src/util/ai-run-evidence.ts +1430 -0
- package/src/util/ai-runner-artifacts.ts +586 -0
- package/src/util/ai-runner-manager-autopilot.ts +961 -0
- package/src/util/ai-runner-manager-policy.ts +5011 -0
- package/src/util/ai-runner-qa-auth.ts +838 -0
- package/src/util/ai-runner-qa-tools.ts +3536 -0
- package/src/util/aicoder-runner-v6.ts +3121 -0
- package/src/util/common.ts +649 -0
- package/src/util/customer-portal-password.ts +183 -0
- package/src/util/error-reporter.ts +332 -0
- package/src/util/error-tracking.ts +79 -0
- package/src/util/openai-usage-cost.ts +114 -0
- package/src/util/report-builder-unwinds.ts +180 -0
- package/src/util/runner-process-janitor.ts +219 -0
- package/src/util/schema-report-builder.ts +448 -0
- package/src/util/slow-query-reporter.ts +216 -0
- package/src/util/subscription-dependency-context.ts +1096 -0
- package/src/util/support-runner-v5.ts +10040 -0
- package/src/util/tokenizer.ts +38 -0
- package/src/workers/codex-runner.worker.ts +142 -0
- package/start_server.sh +5 -0
- package/tests/ai-assistant-corpus-build.ts +484 -0
- package/tests/ai-assistant-corpus-replay-e2e.ts +774 -0
- package/tests/ai-assistant-data-parity-e2e.ts +1989 -0
- package/tests/ai-assistant-eval-triage.ts +831 -0
- package/tests/ai-assistant-openai-e2e.ts +1061 -0
- package/tests/ai-assistant-openai-git-e2e.ts +155 -0
- package/tests/ai-assistant-preflight-matrix.ts +215 -0
- package/tests/ai-assistant-routing-eval.test.ts +585 -0
- package/tests/ai-assistant-snf-live-eval.ts +975 -0
- package/tests/ai-assistant-utils.test.ts +4834 -0
- package/tests/ai-manager-autopilot-snapshot.test.ts +193 -0
- package/tests/ai-manager-recovery-checkpoint.test.ts +1383 -0
- package/tests/ai-run-eval.test.ts +132 -0
- package/tests/ai-run-evidence.test.ts +3773 -0
- package/tests/ai-runner-contract.test.ts +515 -0
- package/tests/aicoder-runner-v6.test.ts +822 -0
- package/tests/error-reporter.test.ts +145 -0
- package/tests/method-publication-generator.test.ts +46 -0
- package/tests/report-builder-linking.test.ts +79 -0
- package/tests/resolveio-platform-intelligence.test.ts +352 -0
- package/tests/server-app-cron-owner.test.ts +127 -0
- package/tests/subscription-connect-race.test.ts +158 -0
- package/tests/subscription-dependency-context.test.ts +324 -0
- package/tests/subscription-manager-collection-tracking.test.ts +86 -0
- package/tests/subscription-manager-invalidation.test.ts +86 -0
- package/tests/support-runner-v5.test.ts +3201 -0
- package/tsconfig.json +34 -0
- package/ai/assistant-core-heuristics.d.ts +0 -11
- package/ai/assistant-core-heuristics.js +0 -356
- package/ai/assistant-core-heuristics.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory-corpus.d.ts +0 -3
- package/ai/resolveio-platform-intelligence-memory-corpus.js +0 -214
- package/ai/resolveio-platform-intelligence-memory-corpus.js.map +0 -1
- package/ai/resolveio-platform-intelligence-memory.d.ts +0 -20
- package/ai/resolveio-platform-intelligence-memory.js +0 -341
- package/ai/resolveio-platform-intelligence-memory.js.map +0 -1
- package/ai/resolveio-platform-intelligence-types.js +0 -4
- package/ai/resolveio-platform-intelligence-types.js.map +0 -1
- package/ai/resolveio-platform-intelligence.d.ts +0 -6
- package/ai/resolveio-platform-intelligence.js +0 -463
- package/ai/resolveio-platform-intelligence.js.map +0 -1
- package/client-server-app.d.ts +0 -1
- package/client-server-app.js +0 -68
- package/client-server-app.js.map +0 -1
- package/collections/ai-run.collection.d.ts +0 -3
- package/collections/ai-run.collection.js +0 -170
- package/collections/ai-run.collection.js.map +0 -1
- package/collections/ai-terminal-conversation.collection.d.ts +0 -2
- package/collections/ai-terminal-conversation.collection.js +0 -140
- package/collections/ai-terminal-conversation.collection.js.map +0 -1
- package/collections/ai-terminal-issue-report.collection.d.ts +0 -2
- package/collections/ai-terminal-issue-report.collection.js +0 -148
- package/collections/ai-terminal-issue-report.collection.js.map +0 -1
- package/collections/ai-terminal-message.collection.d.ts +0 -2
- package/collections/ai-terminal-message.collection.js +0 -121
- package/collections/ai-terminal-message.collection.js.map +0 -1
- package/collections/app-setting.collection.d.ts +0 -3
- package/collections/app-setting.collection.js +0 -103
- package/collections/app-setting.collection.js.map +0 -1
- package/collections/app-status.collection.d.ts +0 -3
- package/collections/app-status.collection.js +0 -57
- package/collections/app-status.collection.js.map +0 -1
- package/collections/communication-metric.collection.d.ts +0 -2
- package/collections/communication-metric.collection.js +0 -133
- package/collections/communication-metric.collection.js.map +0 -1
- package/collections/counter.collection.d.ts +0 -3
- package/collections/counter.collection.js +0 -56
- package/collections/counter.collection.js.map +0 -1
- package/collections/cron-job-history.collection.d.ts +0 -3
- package/collections/cron-job-history.collection.js +0 -137
- package/collections/cron-job-history.collection.js.map +0 -1
- package/collections/cron-job.collection.d.ts +0 -3
- package/collections/cron-job.collection.js +0 -92
- package/collections/cron-job.collection.js.map +0 -1
- package/collections/customer-notification.collection.d.ts +0 -3
- package/collections/customer-notification.collection.js +0 -130
- package/collections/customer-notification.collection.js.map +0 -1
- package/collections/customer-portal-password.collection.d.ts +0 -3
- package/collections/customer-portal-password.collection.js +0 -75
- package/collections/customer-portal-password.collection.js.map +0 -1
- package/collections/email-history.collection.d.ts +0 -3
- package/collections/email-history.collection.js +0 -134
- package/collections/email-history.collection.js.map +0 -1
- package/collections/email-verified.collection.d.ts +0 -3
- package/collections/email-verified.collection.js +0 -62
- package/collections/email-verified.collection.js.map +0 -1
- package/collections/file.collection.d.ts +0 -3
- package/collections/file.collection.js +0 -74
- package/collections/file.collection.js.map +0 -1
- package/collections/flag-update.collection.d.ts +0 -3
- package/collections/flag-update.collection.js +0 -57
- package/collections/flag-update.collection.js.map +0 -1
- package/collections/flag.collection.d.ts +0 -3
- package/collections/flag.collection.js +0 -57
- package/collections/flag.collection.js.map +0 -1
- package/collections/log-method-latency.collection.d.ts +0 -3
- package/collections/log-method-latency.collection.js +0 -77
- package/collections/log-method-latency.collection.js.map +0 -1
- package/collections/log-subscription.collection.d.ts +0 -3
- package/collections/log-subscription.collection.js +0 -80
- package/collections/log-subscription.collection.js.map +0 -1
- package/collections/log.collection.d.ts +0 -3
- package/collections/log.collection.js +0 -93
- package/collections/log.collection.js.map +0 -1
- package/collections/logged-in-users.collection.d.ts +0 -3
- package/collections/logged-in-users.collection.js +0 -67
- package/collections/logged-in-users.collection.js.map +0 -1
- package/collections/monitor-cpu.collection.d.ts +0 -3
- package/collections/monitor-cpu.collection.js +0 -65
- package/collections/monitor-cpu.collection.js.map +0 -1
- package/collections/monitor-function.collection.d.ts +0 -3
- package/collections/monitor-function.collection.js +0 -74
- package/collections/monitor-function.collection.js.map +0 -1
- package/collections/monitor-memory.collection.d.ts +0 -3
- package/collections/monitor-memory.collection.js +0 -77
- package/collections/monitor-memory.collection.js.map +0 -1
- package/collections/monitor-mongo.collection.d.ts +0 -3
- package/collections/monitor-mongo.collection.js +0 -71
- package/collections/monitor-mongo.collection.js.map +0 -1
- package/collections/notification.collection.d.ts +0 -3
- package/collections/notification.collection.js +0 -57
- package/collections/notification.collection.js.map +0 -1
- package/collections/openai-usage-ledger.collection.d.ts +0 -2
- package/collections/openai-usage-ledger.collection.js +0 -188
- package/collections/openai-usage-ledger.collection.js.map +0 -1
- package/collections/report-builder-dashboard-builder.collection.d.ts +0 -3
- package/collections/report-builder-dashboard-builder.collection.js +0 -109
- package/collections/report-builder-dashboard-builder.collection.js.map +0 -1
- package/collections/report-builder-library.collection.d.ts +0 -3
- package/collections/report-builder-library.collection.js +0 -87
- package/collections/report-builder-library.collection.js.map +0 -1
- package/collections/report-builder-report.collection.d.ts +0 -4
- package/collections/report-builder-report.collection.js +0 -184
- package/collections/report-builder-report.collection.js.map +0 -1
- package/collections/user-group.collection.d.ts +0 -4
- package/collections/user-group.collection.js +0 -89
- package/collections/user-group.collection.js.map +0 -1
- package/collections/user-guide.collection.d.ts +0 -3
- package/collections/user-guide.collection.js +0 -57
- package/collections/user-guide.collection.js.map +0 -1
- package/collections/user.collection.d.ts +0 -4
- package/collections/user.collection.js +0 -180
- package/collections/user.collection.js.map +0 -1
- package/cron/cron.d.ts +0 -14
- package/cron/cron.js +0 -216
- package/cron/cron.js.map +0 -1
- package/fixtures/cron-jobs.d.ts +0 -1
- package/fixtures/cron-jobs.js +0 -150
- package/fixtures/cron-jobs.js.map +0 -1
- package/fixtures/init.d.ts +0 -1
- package/fixtures/init.js +0 -91
- package/fixtures/init.js.map +0 -1
- package/http/auth.d.ts +0 -2
- package/http/auth.js +0 -951
- package/http/auth.js.map +0 -1
- package/http/health.d.ts +0 -1
- package/http/health.js +0 -11
- package/http/health.js.map +0 -1
- package/http/home.d.ts +0 -1
- package/http/home.js +0 -134
- package/http/home.js.map +0 -1
- package/http/slow-query-publication.d.ts +0 -2
- package/http/slow-query-publication.js +0 -99
- package/http/slow-query-publication.js.map +0 -1
- package/index.d.ts +0 -1
- package/index.js +0 -19
- package/index.js.map +0 -1
- package/managers/ai-assistant-codex-manager.manager.d.ts +0 -67
- package/managers/ai-assistant-codex-manager.manager.js +0 -1113
- package/managers/ai-assistant-codex-manager.manager.js.map +0 -1
- package/managers/ai-run-evidence.manager.d.ts +0 -36
- package/managers/ai-run-evidence.manager.js +0 -377
- package/managers/ai-run-evidence.manager.js.map +0 -1
- package/managers/communication-metric.manager.d.ts +0 -16
- package/managers/communication-metric.manager.js +0 -134
- package/managers/communication-metric.manager.js.map +0 -1
- package/managers/cron.manager.d.ts +0 -20
- package/managers/cron.manager.js +0 -534
- package/managers/cron.manager.js.map +0 -1
- package/managers/customer-notification-content.manager.d.ts +0 -55
- package/managers/customer-notification-content.manager.js +0 -158
- package/managers/customer-notification-content.manager.js.map +0 -1
- package/managers/diagnostic-manager-bootstrap.d.ts +0 -9
- package/managers/diagnostic-manager-bootstrap.js +0 -260
- package/managers/diagnostic-manager-bootstrap.js.map +0 -1
- package/managers/error-auto-fix.manager.d.ts +0 -149
- package/managers/error-auto-fix.manager.js +0 -3064
- package/managers/error-auto-fix.manager.js.map +0 -1
- package/managers/local-log.manager.d.ts +0 -18
- package/managers/local-log.manager.js +0 -88
- package/managers/local-log.manager.js.map +0 -1
- package/managers/method.manager.d.ts +0 -84
- package/managers/method.manager.js +0 -1964
- package/managers/method.manager.js.map +0 -1
- package/managers/mongo.manager.d.ts +0 -224
- package/managers/mongo.manager.js +0 -5000
- package/managers/mongo.manager.js.map +0 -1
- package/managers/monitor.manager.d.ts +0 -70
- package/managers/monitor.manager.js +0 -550
- package/managers/monitor.manager.js.map +0 -1
- package/managers/openai-usage-ledger.manager.d.ts +0 -30
- package/managers/openai-usage-ledger.manager.js +0 -142
- package/managers/openai-usage-ledger.manager.js.map +0 -1
- package/managers/slow-query-verifier.manager.d.ts +0 -144
- package/managers/slow-query-verifier.manager.js +0 -3857
- package/managers/slow-query-verifier.manager.js.map +0 -1
- package/managers/slow-query.manager.d.ts +0 -28
- package/managers/slow-query.manager.js +0 -468
- package/managers/slow-query.manager.js.map +0 -1
- package/managers/subscription.manager.d.ts +0 -169
- package/managers/subscription.manager.js +0 -3434
- package/managers/subscription.manager.js.map +0 -1
- package/managers/websocket.manager.d.ts +0 -73
- package/managers/websocket.manager.js +0 -673
- package/managers/websocket.manager.js.map +0 -1
- package/managers/worker-dispatcher.manager.d.ts +0 -120
- package/managers/worker-dispatcher.manager.js +0 -1266
- package/managers/worker-dispatcher.manager.js.map +0 -1
- package/managers/worker-server.manager.d.ts +0 -35
- package/managers/worker-server.manager.js +0 -582
- package/managers/worker-server.manager.js.map +0 -1
- package/methods/accounts.d.ts +0 -2
- package/methods/accounts.js +0 -624
- package/methods/accounts.js.map +0 -1
- package/methods/ai-terminal.d.ts +0 -458
- package/methods/ai-terminal.js +0 -27991
- package/methods/ai-terminal.js.map +0 -1
- package/methods/app-settings.d.ts +0 -2
- package/methods/app-settings.js +0 -169
- package/methods/app-settings.js.map +0 -1
- package/methods/aws.d.ts +0 -2
- package/methods/aws.js +0 -877
- package/methods/aws.js.map +0 -1
- package/methods/collections.d.ts +0 -2
- package/methods/collections.js +0 -719
- package/methods/collections.js.map +0 -1
- package/methods/counters.d.ts +0 -2
- package/methods/counters.js +0 -113
- package/methods/counters.js.map +0 -1
- package/methods/cron-jobs.d.ts +0 -2
- package/methods/cron-jobs.js +0 -2475
- package/methods/cron-jobs.js.map +0 -1
- package/methods/customer-notifications.d.ts +0 -2
- package/methods/customer-notifications.js +0 -528
- package/methods/customer-notifications.js.map +0 -1
- package/methods/diagnostics.d.ts +0 -2
- package/methods/diagnostics.js +0 -703
- package/methods/diagnostics.js.map +0 -1
- package/methods/flag-updates.d.ts +0 -2
- package/methods/flag-updates.js +0 -8
- package/methods/flag-updates.js.map +0 -1
- package/methods/flags.d.ts +0 -2
- package/methods/flags.js +0 -8
- package/methods/flags.js.map +0 -1
- package/methods/logs.d.ts +0 -2
- package/methods/logs.js +0 -751
- package/methods/logs.js.map +0 -1
- package/methods/mongo-explorer.d.ts +0 -2
- package/methods/mongo-explorer.js +0 -1808
- package/methods/mongo-explorer.js.map +0 -1
- package/methods/monitor.d.ts +0 -2
- package/methods/monitor.js +0 -543
- package/methods/monitor.js.map +0 -1
- package/methods/pdf.d.ts +0 -2
- package/methods/pdf.js +0 -1216
- package/methods/pdf.js.map +0 -1
- package/methods/publications.d.ts +0 -1
- package/methods/publications.js +0 -183
- package/methods/publications.js.map +0 -1
- package/methods/report-builder.d.ts +0 -2
- package/methods/report-builder.js +0 -3094
- package/methods/report-builder.js.map +0 -1
- package/methods/support.d.ts +0 -2
- package/methods/support.js +0 -430
- package/methods/support.js.map +0 -1
- package/models/ai-run.model.d.ts +0 -19
- package/models/ai-run.model.js +0 -4
- package/models/ai-run.model.js.map +0 -1
- package/models/ai-terminal-conversation.model.d.ts +0 -17
- package/models/ai-terminal-conversation.model.js +0 -4
- package/models/ai-terminal-conversation.model.js.map +0 -1
- package/models/ai-terminal-issue-report.model.d.ts +0 -19
- package/models/ai-terminal-issue-report.model.js +0 -4
- package/models/ai-terminal-issue-report.model.js.map +0 -1
- package/models/ai-terminal-message.model.d.ts +0 -22
- package/models/ai-terminal-message.model.js +0 -4
- package/models/ai-terminal-message.model.js.map +0 -1
- package/models/app-setting.model.d.ts +0 -16
- package/models/app-setting.model.js +0 -4
- package/models/app-setting.model.js.map +0 -1
- package/models/app-status.model.js +0 -4
- package/models/app-status.model.js.map +0 -1
- package/models/billing-logged-in-users.model.js +0 -4
- package/models/billing-logged-in-users.model.js.map +0 -1
- package/models/collection-document.model.d.ts +0 -21
- package/models/collection-document.model.js +0 -4
- package/models/collection-document.model.js.map +0 -1
- package/models/communication-metric.model.d.ts +0 -20
- package/models/communication-metric.model.js +0 -4
- package/models/communication-metric.model.js.map +0 -1
- package/models/counter.model.js +0 -4
- package/models/counter.model.js.map +0 -1
- package/models/cron-job-history.model.d.ts +0 -15
- package/models/cron-job-history.model.js +0 -4
- package/models/cron-job-history.model.js.map +0 -1
- package/models/cron-job.model.d.ts +0 -14
- package/models/cron-job.model.js +0 -4
- package/models/cron-job.model.js.map +0 -1
- package/models/customer-notification.model.d.ts +0 -26
- package/models/customer-notification.model.js +0 -4
- package/models/customer-notification.model.js.map +0 -1
- package/models/customer-portal-password.model.d.ts +0 -11
- package/models/customer-portal-password.model.js +0 -4
- package/models/customer-portal-password.model.js.map +0 -1
- package/models/dialog.model.d.ts +0 -23
- package/models/dialog.model.js +0 -4
- package/models/dialog.model.js.map +0 -1
- package/models/email-history.model.d.ts +0 -32
- package/models/email-history.model.js.map +0 -1
- package/models/email-verified.model.js +0 -4
- package/models/email-verified.model.js.map +0 -1
- package/models/file.model.js +0 -4
- package/models/file.model.js.map +0 -1
- package/models/flag-update.model.js +0 -4
- package/models/flag-update.model.js.map +0 -1
- package/models/flag.model.js +0 -4
- package/models/flag.model.js.map +0 -1
- package/models/log-method-latency.model.d.ts +0 -10
- package/models/log-method-latency.model.js +0 -4
- package/models/log-method-latency.model.js.map +0 -1
- package/models/log-subscription.model.js +0 -4
- package/models/log-subscription.model.js.map +0 -1
- package/models/log.model.d.ts +0 -17
- package/models/log.model.js +0 -4
- package/models/log.model.js.map +0 -1
- package/models/logged-in-users.model.js +0 -4
- package/models/logged-in-users.model.js.map +0 -1
- package/models/method-response.model.js +0 -4
- package/models/method-response.model.js.map +0 -1
- package/models/method.model.d.ts +0 -26
- package/models/method.model.js +0 -4
- package/models/method.model.js.map +0 -1
- package/models/monitor-cpu.model.js +0 -4
- package/models/monitor-cpu.model.js.map +0 -1
- package/models/monitor-function.model.d.ts +0 -14
- package/models/monitor-function.model.js +0 -4
- package/models/monitor-function.model.js.map +0 -1
- package/models/monitor-memory.model.d.ts +0 -15
- package/models/monitor-memory.model.js +0 -4
- package/models/monitor-memory.model.js.map +0 -1
- package/models/monitor-mongo.model.d.ts +0 -13
- package/models/monitor-mongo.model.js +0 -4
- package/models/monitor-mongo.model.js.map +0 -1
- package/models/notification.model.js +0 -4
- package/models/notification.model.js.map +0 -1
- package/models/openai-usage-ledger.model.d.ts +0 -30
- package/models/openai-usage-ledger.model.js +0 -4
- package/models/openai-usage-ledger.model.js.map +0 -1
- package/models/pagination.model.d.ts +0 -11
- package/models/pagination.model.js +0 -28
- package/models/pagination.model.js.map +0 -1
- package/models/permission.model.d.ts +0 -12
- package/models/permission.model.js +0 -4
- package/models/permission.model.js.map +0 -1
- package/models/report-builder-dashboard-builder.model.d.ts +0 -25
- package/models/report-builder-dashboard-builder.model.js +0 -4
- package/models/report-builder-dashboard-builder.model.js.map +0 -1
- package/models/report-builder-library.model.d.ts +0 -17
- package/models/report-builder-library.model.js +0 -4
- package/models/report-builder-library.model.js.map +0 -1
- package/models/report-builder-report.model.d.ts +0 -121
- package/models/report-builder-report.model.js +0 -4
- package/models/report-builder-report.model.js.map +0 -1
- package/models/report-builder.model.d.ts +0 -61
- package/models/report-builder.model.js +0 -4
- package/models/report-builder.model.js.map +0 -1
- package/models/select-data-label.model.d.ts +0 -9
- package/models/select-data-label.model.js +0 -4
- package/models/select-data-label.model.js.map +0 -1
- package/models/server-message.model.d.ts +0 -32
- package/models/server-message.model.js +0 -4
- package/models/server-message.model.js.map +0 -1
- package/models/slow-query-report.model.d.ts +0 -23
- package/models/slow-query-report.model.js +0 -4
- package/models/slow-query-report.model.js.map +0 -1
- package/models/subscription.model.d.ts +0 -31
- package/models/subscription.model.js +0 -4
- package/models/subscription.model.js.map +0 -1
- package/models/support-ticket.model.d.ts +0 -87
- package/models/support-ticket.model.js +0 -4
- package/models/support-ticket.model.js.map +0 -1
- package/models/user-group.model.d.ts +0 -20
- package/models/user-group.model.js +0 -4
- package/models/user-group.model.js.map +0 -1
- package/models/user-guide.model.js +0 -4
- package/models/user-guide.model.js.map +0 -1
- package/models/user.model.d.ts +0 -84
- package/models/user.model.js +0 -4
- package/models/user.model.js.map +0 -1
- package/private/images/ResolveIO.png +0 -0
- package/public_api.js +0 -127
- package/public_api.js.map +0 -1
- package/publications/ai-terminal.d.ts +0 -1
- package/publications/ai-terminal.js +0 -122
- package/publications/ai-terminal.js.map +0 -1
- package/publications/app-settings.d.ts +0 -2
- package/publications/app-settings.js +0 -28
- package/publications/app-settings.js.map +0 -1
- package/publications/app-status.d.ts +0 -2
- package/publications/app-status.js +0 -16
- package/publications/app-status.js.map +0 -1
- package/publications/cron-jobs.d.ts +0 -2
- package/publications/cron-jobs.js +0 -88
- package/publications/cron-jobs.js.map +0 -1
- package/publications/customer-notifications.d.ts +0 -2
- package/publications/customer-notifications.js +0 -161
- package/publications/customer-notifications.js.map +0 -1
- package/publications/files.d.ts +0 -2
- package/publications/files.js +0 -36
- package/publications/files.js.map +0 -1
- package/publications/flags-update.d.ts +0 -2
- package/publications/flags-update.js +0 -22
- package/publications/flags-update.js.map +0 -1
- package/publications/flags.d.ts +0 -2
- package/publications/flags.js +0 -22
- package/publications/flags.js.map +0 -1
- package/publications/logs.d.ts +0 -2
- package/publications/logs.js +0 -164
- package/publications/logs.js.map +0 -1
- package/publications/notifications.d.ts +0 -2
- package/publications/notifications.js +0 -16
- package/publications/notifications.js.map +0 -1
- package/publications/report-builder-dashboard-builders.d.ts +0 -2
- package/publications/report-builder-dashboard-builders.js +0 -42
- package/publications/report-builder-dashboard-builders.js.map +0 -1
- package/publications/report-builder-libraries.d.ts +0 -2
- package/publications/report-builder-libraries.js +0 -90
- package/publications/report-builder-libraries.js.map +0 -1
- package/publications/report-builder-reports.d.ts +0 -2
- package/publications/report-builder-reports.js +0 -50
- package/publications/report-builder-reports.js.map +0 -1
- package/publications/super-admin.d.ts +0 -2
- package/publications/super-admin.js +0 -16
- package/publications/super-admin.js.map +0 -1
- package/publications/user-groups.d.ts +0 -1
- package/publications/user-groups.js +0 -16
- package/publications/user-groups.js.map +0 -1
- package/publications/user-guides.d.ts +0 -1
- package/publications/user-guides.js +0 -16
- package/publications/user-guides.js.map +0 -1
- package/resolveio-server-app.d.ts +0 -70
- package/resolveio-server-app.js +0 -801
- package/resolveio-server-app.js.map +0 -1
- package/server-app.d.ts +0 -228
- package/server-app.js +0 -3566
- package/server-app.js.map +0 -1
- package/services/codex-client.d.ts +0 -128
- package/services/codex-client.js +0 -1629
- package/services/codex-client.js.map +0 -1
- package/services/openai-client.d.ts +0 -46
- package/services/openai-client.js +0 -318
- package/services/openai-client.js.map +0 -1
- package/types/error-report.d.ts +0 -25
- package/types/error-report.js +0 -4
- package/types/error-report.js.map +0 -1
- package/types/slow-query-report.d.ts +0 -27
- package/types/slow-query-report.js +0 -6
- package/types/slow-query-report.js.map +0 -1
- package/util/ai-qa-policy.d.ts +0 -124
- package/util/ai-qa-policy.js +0 -736
- package/util/ai-qa-policy.js.map +0 -1
- package/util/ai-run-evidence-adapters.d.ts +0 -109
- package/util/ai-run-evidence-adapters.js +0 -7234
- package/util/ai-run-evidence-adapters.js.map +0 -1
- package/util/ai-run-evidence-dashboard.d.ts +0 -88
- package/util/ai-run-evidence-dashboard.js +0 -343
- package/util/ai-run-evidence-dashboard.js.map +0 -1
- package/util/ai-run-evidence-eval.d.ts +0 -86
- package/util/ai-run-evidence-eval.js +0 -1018
- package/util/ai-run-evidence-eval.js.map +0 -1
- package/util/ai-run-evidence.d.ts +0 -244
- package/util/ai-run-evidence.js +0 -1096
- package/util/ai-run-evidence.js.map +0 -1
- package/util/ai-runner-artifacts.d.ts +0 -82
- package/util/ai-runner-artifacts.js +0 -713
- package/util/ai-runner-artifacts.js.map +0 -1
- package/util/ai-runner-manager-autopilot.d.ts +0 -210
- package/util/ai-runner-manager-autopilot.js +0 -642
- package/util/ai-runner-manager-autopilot.js.map +0 -1
- package/util/ai-runner-manager-policy.d.ts +0 -807
- package/util/ai-runner-manager-policy.js +0 -3501
- package/util/ai-runner-manager-policy.js.map +0 -1
- package/util/ai-runner-qa-auth.d.ts +0 -5
- package/util/ai-runner-qa-auth.js +0 -839
- package/util/ai-runner-qa-auth.js.map +0 -1
- package/util/ai-runner-qa-tools.d.ts +0 -26
- package/util/ai-runner-qa-tools.js +0 -3520
- package/util/ai-runner-qa-tools.js.map +0 -1
- package/util/aicoder-runner-v6.d.ts +0 -426
- package/util/aicoder-runner-v6.js +0 -2464
- package/util/aicoder-runner-v6.js.map +0 -1
- package/util/common.d.ts +0 -31
- package/util/common.js +0 -683
- package/util/common.js.map +0 -1
- package/util/customer-portal-password.d.ts +0 -13
- package/util/customer-portal-password.js +0 -209
- package/util/customer-portal-password.js.map +0 -1
- package/util/error-reporter.d.ts +0 -52
- package/util/error-reporter.js +0 -326
- package/util/error-reporter.js.map +0 -1
- package/util/error-tracking.d.ts +0 -13
- package/util/error-tracking.js +0 -120
- package/util/error-tracking.js.map +0 -1
- package/util/openai-usage-cost.d.ts +0 -6
- package/util/openai-usage-cost.js +0 -103
- package/util/openai-usage-cost.js.map +0 -1
- package/util/report-builder-unwinds.d.ts +0 -15
- package/util/report-builder-unwinds.js +0 -156
- package/util/report-builder-unwinds.js.map +0 -1
- package/util/runner-process-janitor.d.ts +0 -27
- package/util/runner-process-janitor.js +0 -208
- package/util/runner-process-janitor.js.map +0 -1
- package/util/schema-report-builder.d.ts +0 -6
- package/util/schema-report-builder.js +0 -481
- package/util/schema-report-builder.js.map +0 -1
- package/util/slow-query-reporter.d.ts +0 -28
- package/util/slow-query-reporter.js +0 -226
- package/util/slow-query-reporter.js.map +0 -1
- package/util/subscription-dependency-context.d.ts +0 -34
- package/util/subscription-dependency-context.js +0 -1283
- package/util/subscription-dependency-context.js.map +0 -1
- package/util/support-runner-v5.d.ts +0 -1426
- package/util/support-runner-v5.js +0 -7624
- package/util/support-runner-v5.js.map +0 -1
- package/util/tokenizer.d.ts +0 -5
- package/util/tokenizer.js +0 -41
- package/util/tokenizer.js.map +0 -1
- package/workers/codex-runner.worker.d.ts +0 -1
- package/workers/codex-runner.worker.js +0 -192
- package/workers/codex-runner.worker.js.map +0 -1
- /package/{private → src/private}/email-templates/enrollment.html +0 -0
- /package/{private → src/private}/email-templates/forgot-password.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-deleted.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket-modified.html +0 -0
- /package/{private → src/private}/email-templates/support-ticket.html +0 -0
- /package/{public_api.d.ts → src/public_api.ts} +0 -0
|
@@ -1,3094 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
24
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
var __read = (this && this.__read) || function (o, n) {
|
|
50
|
-
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
51
|
-
if (!m) return o;
|
|
52
|
-
var i = m.call(o), r, ar = [], e;
|
|
53
|
-
try {
|
|
54
|
-
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
55
|
-
}
|
|
56
|
-
catch (error) { e = { error: error }; }
|
|
57
|
-
finally {
|
|
58
|
-
try {
|
|
59
|
-
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
60
|
-
}
|
|
61
|
-
finally { if (e) throw e.error; }
|
|
62
|
-
}
|
|
63
|
-
return ar;
|
|
64
|
-
};
|
|
65
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
66
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
67
|
-
if (ar || !(i in from)) {
|
|
68
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
69
|
-
ar[i] = from[i];
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
73
|
-
};
|
|
74
|
-
var __values = (this && this.__values) || function(o) {
|
|
75
|
-
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
76
|
-
if (m) return m.call(o);
|
|
77
|
-
if (o && typeof o.length === "number") return {
|
|
78
|
-
next: function () {
|
|
79
|
-
if (o && i >= o.length) o = void 0;
|
|
80
|
-
return { value: o && o[i++], done: !o };
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
|
-
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
84
|
-
};
|
|
85
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
86
|
-
exports.loadReportBuilderMethods = loadReportBuilderMethods;
|
|
87
|
-
var simpl_schema_1 = require("simpl-schema");
|
|
88
|
-
var report_builder_report_collection_1 = require("../collections/report-builder-report.collection");
|
|
89
|
-
var user_collection_1 = require("../collections/user.collection");
|
|
90
|
-
var openai_usage_ledger_manager_1 = require("../managers/openai-usage-ledger.manager");
|
|
91
|
-
var pagination_model_1 = require("../models/pagination.model");
|
|
92
|
-
var resolveio_server_app_1 = require("../resolveio-server-app");
|
|
93
|
-
var codex_client_1 = require("../services/codex-client");
|
|
94
|
-
var common_1 = require("../util/common");
|
|
95
|
-
var report_builder_unwinds_1 = require("../util/report-builder-unwinds");
|
|
96
|
-
var schema_report_builder_1 = require("../util/schema-report-builder");
|
|
97
|
-
var tokenizer_1 = require("../util/tokenizer");
|
|
98
|
-
var ai_terminal_1 = require("./ai-terminal");
|
|
99
|
-
var DEFAULT_REPORT_BUILDER_CODEX_TIMEOUT_MS = 60000;
|
|
100
|
-
var reportBuilderCodexClient = null;
|
|
101
|
-
function loadReportBuilderMethods(methodManager) {
|
|
102
|
-
methodManager.methods({
|
|
103
|
-
reportBuilderAiSuggest: {
|
|
104
|
-
check: new simpl_schema_1.default({
|
|
105
|
-
payload: {
|
|
106
|
-
type: Object,
|
|
107
|
-
blackbox: true
|
|
108
|
-
}
|
|
109
|
-
}),
|
|
110
|
-
function: function (payload) {
|
|
111
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
112
|
-
return __generator(this, function (_a) {
|
|
113
|
-
switch (_a.label) {
|
|
114
|
-
case 0: return [4 /*yield*/, executeReportBuilderAi(payload || {}, this)];
|
|
115
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
reportbuilderreportWithId: {
|
|
122
|
-
check: new simpl_schema_1.default({
|
|
123
|
-
id: {
|
|
124
|
-
type: String
|
|
125
|
-
}
|
|
126
|
-
}),
|
|
127
|
-
function: function (id) {
|
|
128
|
-
return report_builder_report_collection_1.ReportBuilderReports.findOne({ _id: id });
|
|
129
|
-
}
|
|
130
|
-
},
|
|
131
|
-
reportBuilderBuildTree: {
|
|
132
|
-
check: new simpl_schema_1.default({
|
|
133
|
-
collection_root: {
|
|
134
|
-
type: String
|
|
135
|
-
},
|
|
136
|
-
collectionJoins: {
|
|
137
|
-
type: Array,
|
|
138
|
-
optional: true
|
|
139
|
-
},
|
|
140
|
-
'collectionJoins.$': {
|
|
141
|
-
type: Object
|
|
142
|
-
},
|
|
143
|
-
'collectionJoins.$.collection': {
|
|
144
|
-
type: String
|
|
145
|
-
},
|
|
146
|
-
'collectionJoins.$.alias': {
|
|
147
|
-
type: String,
|
|
148
|
-
optional: true
|
|
149
|
-
},
|
|
150
|
-
'collectionJoins.$.local_key': {
|
|
151
|
-
type: String,
|
|
152
|
-
optional: true
|
|
153
|
-
},
|
|
154
|
-
'collectionJoins.$.foreign_key': {
|
|
155
|
-
type: String,
|
|
156
|
-
optional: true
|
|
157
|
-
}
|
|
158
|
-
}),
|
|
159
|
-
function: function (collection_root, collectionJoins) {
|
|
160
|
-
if (collectionJoins === void 0) { collectionJoins = []; }
|
|
161
|
-
var baseRootTree = buildCollectionTree(collection_root);
|
|
162
|
-
var collectionTrees = [
|
|
163
|
-
{
|
|
164
|
-
collection: collection_root,
|
|
165
|
-
alias: (0, common_1.toTitleCase)(collection_root.replace(/\_/g, ' ').replace(/-/g, ' ')),
|
|
166
|
-
lookup_as: '',
|
|
167
|
-
tree: (0, common_1.deepCopy)(baseRootTree)
|
|
168
|
-
}
|
|
169
|
-
];
|
|
170
|
-
var rootTree = baseRootTree;
|
|
171
|
-
(collectionJoins || []).forEach(function (join, joinIndex) {
|
|
172
|
-
var joinLocalKey = join.local_key && join.local_key.trim().length ? join.local_key : '_id';
|
|
173
|
-
var joinForeignKey = join.foreign_key && join.foreign_key.trim().length ? join.foreign_key : '_id';
|
|
174
|
-
var joinAlias = buildJoinAlias(join, joinIndex);
|
|
175
|
-
var joinNode = buildJoinLookupNode(collection_root, __assign(__assign({}, join), { local_key: joinLocalKey, foreign_key: joinForeignKey }), joinAlias);
|
|
176
|
-
var joinTree = buildCollectionTree(join.collection, joinNode);
|
|
177
|
-
joinNode.children = joinTree.children;
|
|
178
|
-
joinNode.is_join = true;
|
|
179
|
-
rootTree.children.push(joinNode);
|
|
180
|
-
collectionTrees.push({
|
|
181
|
-
collection: join.collection,
|
|
182
|
-
alias: joinAlias,
|
|
183
|
-
lookup_as: joinNode.lookup_as,
|
|
184
|
-
tree: (0, common_1.deepCopy)(joinTree)
|
|
185
|
-
});
|
|
186
|
-
});
|
|
187
|
-
return Promise.resolve({
|
|
188
|
-
isLeaf: false,
|
|
189
|
-
children: rootTree.children,
|
|
190
|
-
trees: collectionTrees
|
|
191
|
-
});
|
|
192
|
-
}
|
|
193
|
-
},
|
|
194
|
-
reportBuilderGetDistinctValue: {
|
|
195
|
-
check: new simpl_schema_1.default({
|
|
196
|
-
treeLeaf: {
|
|
197
|
-
type: Object,
|
|
198
|
-
blackbox: true
|
|
199
|
-
}
|
|
200
|
-
}),
|
|
201
|
-
function: function (treeLeaf) {
|
|
202
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
203
|
-
var fieldPath;
|
|
204
|
-
return __generator(this, function (_a) {
|
|
205
|
-
if (treeLeaf.fieldType === 'String') {
|
|
206
|
-
fieldPath = (treeLeaf && typeof treeLeaf.fieldPath === 'string') ? treeLeaf.fieldPath : '';
|
|
207
|
-
if (fieldPath.includes('(Lookup') || treeLeaf.lookup_collection) {
|
|
208
|
-
return [2 /*return*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, fieldPath.replace(/^.+\(.+\) \(Lookup.*\)\.\$\./g, '').replace(/\.\$/g, ''))];
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
return [2 /*return*/, (0, schema_report_builder_1.mongoCommand)('distinct', treeLeaf.collection_name, fieldPath.replace(/\.\$/g, ''))];
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
return [2 /*return*/, []];
|
|
216
|
-
}
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
});
|
|
219
|
-
});
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
reportBuilderGetResults: {
|
|
223
|
-
bypassSession: true,
|
|
224
|
-
check: new simpl_schema_1.default({
|
|
225
|
-
reportType: {
|
|
226
|
-
type: String
|
|
227
|
-
},
|
|
228
|
-
rootCollectionName: {
|
|
229
|
-
type: String
|
|
230
|
-
},
|
|
231
|
-
options: {
|
|
232
|
-
type: pagination_model_1.PaginationOptionsSchema
|
|
233
|
-
},
|
|
234
|
-
filters: {
|
|
235
|
-
type: Array,
|
|
236
|
-
optional: true
|
|
237
|
-
},
|
|
238
|
-
'filters.$': {
|
|
239
|
-
type: Object,
|
|
240
|
-
blackbox: true,
|
|
241
|
-
optional: true
|
|
242
|
-
},
|
|
243
|
-
filterArrays: {
|
|
244
|
-
type: Array,
|
|
245
|
-
optional: true
|
|
246
|
-
},
|
|
247
|
-
'filterArrays.$': {
|
|
248
|
-
type: Object,
|
|
249
|
-
blackbox: true,
|
|
250
|
-
optional: true
|
|
251
|
-
},
|
|
252
|
-
filterArrayFields: {
|
|
253
|
-
type: Array,
|
|
254
|
-
optional: true
|
|
255
|
-
},
|
|
256
|
-
'filterArrayFields.$': {
|
|
257
|
-
type: Object,
|
|
258
|
-
blackbox: true,
|
|
259
|
-
optional: true
|
|
260
|
-
},
|
|
261
|
-
selectedFields: {
|
|
262
|
-
type: Array,
|
|
263
|
-
optional: true
|
|
264
|
-
},
|
|
265
|
-
'selectedFields.$': {
|
|
266
|
-
type: Object,
|
|
267
|
-
optional: true,
|
|
268
|
-
blackbox: true
|
|
269
|
-
},
|
|
270
|
-
customFields: {
|
|
271
|
-
type: Array,
|
|
272
|
-
optional: true
|
|
273
|
-
},
|
|
274
|
-
'customFields.$': {
|
|
275
|
-
type: Object,
|
|
276
|
-
optional: true,
|
|
277
|
-
blackbox: true
|
|
278
|
-
},
|
|
279
|
-
groupsRow: {
|
|
280
|
-
type: Array
|
|
281
|
-
},
|
|
282
|
-
'groupsRow.$': {
|
|
283
|
-
type: Object,
|
|
284
|
-
blackbox: true
|
|
285
|
-
},
|
|
286
|
-
fieldsTotal: {
|
|
287
|
-
type: Array
|
|
288
|
-
},
|
|
289
|
-
'fieldsTotal.$': {
|
|
290
|
-
type: Object,
|
|
291
|
-
blackbox: true
|
|
292
|
-
},
|
|
293
|
-
fieldsLink: {
|
|
294
|
-
type: Array
|
|
295
|
-
},
|
|
296
|
-
'fieldsLink.$': {
|
|
297
|
-
type: Object,
|
|
298
|
-
blackbox: true
|
|
299
|
-
},
|
|
300
|
-
date_field: {
|
|
301
|
-
type: String,
|
|
302
|
-
optional: true
|
|
303
|
-
},
|
|
304
|
-
date_interval: {
|
|
305
|
-
type: String,
|
|
306
|
-
optional: true
|
|
307
|
-
},
|
|
308
|
-
displayType: {
|
|
309
|
-
type: String,
|
|
310
|
-
optional: true
|
|
311
|
-
}
|
|
312
|
-
}),
|
|
313
|
-
function: function (reportType_1, rootCollectionName_1, rootOptions_1) {
|
|
314
|
-
return __awaiter(this, arguments, void 0, function (reportType, rootCollectionName, rootOptions, filters, filterArrays, filterArrayFields, selectedFields, customFields, groupsRow, fieldsTotal, fieldsLink, date_field, date_interval, displayType) {
|
|
315
|
-
var modelCollection, datePaths, reportBuilderTimezone, lookupAliases, _a, rootFilters_1, lookupFilters_1, additionalCollectionsMap_1, additionalCollections, unionQuery_1, _b, sortToUse, layoutSortAdd, remappedFilters, remappedArrayFilters, postMatchAnd, readPreference_1, queryResult_1, err_1, tmpRes_1, query_1, initialQueryMatchCondition_1, sizes_1, divFields_1, queryMatchConditionLookup_1, queryGroup_1, groupedSorts_1, dateFieldPath, dateFieldExpr, utcHourExpr, utcMinuteExpr, utcSecondExpr, utcDayExpr, tzDayExpr, useUtcForDateOnlyExpr, groupingTimezoneExpr, queryProjection_1, _loop_1, i, readPreference, queryResult, err_2, tmpRes;
|
|
316
|
-
if (filters === void 0) { filters = []; }
|
|
317
|
-
if (filterArrays === void 0) { filterArrays = []; }
|
|
318
|
-
if (filterArrayFields === void 0) { filterArrayFields = []; }
|
|
319
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
320
|
-
if (customFields === void 0) { customFields = []; }
|
|
321
|
-
if (groupsRow === void 0) { groupsRow = []; }
|
|
322
|
-
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
323
|
-
if (fieldsLink === void 0) { fieldsLink = []; }
|
|
324
|
-
if (date_field === void 0) { date_field = ''; }
|
|
325
|
-
if (date_interval === void 0) { date_interval = ''; }
|
|
326
|
-
if (displayType === void 0) { displayType = ''; }
|
|
327
|
-
return __generator(this, function (_c) {
|
|
328
|
-
switch (_c.label) {
|
|
329
|
-
case 0:
|
|
330
|
-
modelCollection = resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(rootCollectionName);
|
|
331
|
-
if (!!modelCollection) return [3 /*break*/, 1];
|
|
332
|
-
throw new Error('Error in Report builder get results: Invalid collection');
|
|
333
|
-
case 1:
|
|
334
|
-
filters = expandLayoutColumnFilters(filters, selectedFields);
|
|
335
|
-
filterArrays = expandLayoutColumnFilters(filterArrays, selectedFields);
|
|
336
|
-
datePaths = collectRootDatePaths(rootCollectionName);
|
|
337
|
-
if (datePaths.size) {
|
|
338
|
-
coerceDateFilters(filters, datePaths);
|
|
339
|
-
coerceDateFilters(filterArrays, datePaths);
|
|
340
|
-
}
|
|
341
|
-
reportBuilderTimezone = process.env.TZ_CLIENT || 'America/Chicago';
|
|
342
|
-
lookupAliases = collectLookupAliases(selectedFields, filterArrayFields, groupsRow);
|
|
343
|
-
_a = splitFiltersByLookup(filters, lookupAliases), rootFilters_1 = _a.rootFilters, lookupFilters_1 = _a.lookupFilters;
|
|
344
|
-
additionalCollectionsMap_1 = new Map();
|
|
345
|
-
(selectedFields || [])
|
|
346
|
-
.filter(function (f) {
|
|
347
|
-
return f &&
|
|
348
|
-
f.lookup_collection &&
|
|
349
|
-
(!f.lookup_local_key || !f.lookup_foreign_key);
|
|
350
|
-
})
|
|
351
|
-
.forEach(function (f) {
|
|
352
|
-
var alias = f.lookup_as || f.lookup_collection;
|
|
353
|
-
var key = "".concat(f.lookup_collection, "::").concat(alias);
|
|
354
|
-
if (!additionalCollectionsMap_1.has(key)) {
|
|
355
|
-
additionalCollectionsMap_1.set(key, { collection: f.lookup_collection, alias: alias });
|
|
356
|
-
}
|
|
357
|
-
});
|
|
358
|
-
additionalCollections = Array.from(additionalCollectionsMap_1.values());
|
|
359
|
-
if (!additionalCollections.length) return [3 /*break*/, 6];
|
|
360
|
-
unionQuery_1 = buildCollectionPipeline(rootCollectionName, '', selectedFields, filters.concat(rootFilters_1 || []), filterArrays.concat(lookupFilters_1 || []), true);
|
|
361
|
-
additionalCollections.forEach(function (cfg) {
|
|
362
|
-
unionQuery_1.push({
|
|
363
|
-
$unionWith: {
|
|
364
|
-
coll: cfg.collection,
|
|
365
|
-
pipeline: buildCollectionPipeline(cfg.collection, cfg.alias, selectedFields, filters.concat(rootFilters_1 || []), filterArrays.concat(lookupFilters_1 || []), false)
|
|
366
|
-
}
|
|
367
|
-
});
|
|
368
|
-
});
|
|
369
|
-
if (rootOptions.sort) {
|
|
370
|
-
_b = buildLayoutSortSpec(rootOptions.sort, selectedFields), sortToUse = _b.sortSpec, layoutSortAdd = _b.addFields;
|
|
371
|
-
if (Object.keys(layoutSortAdd).length) {
|
|
372
|
-
unionQuery_1.push({ $addFields: layoutSortAdd });
|
|
373
|
-
}
|
|
374
|
-
appendSafeSort(unionQuery_1, sortToUse, selectedFields, customFields);
|
|
375
|
-
}
|
|
376
|
-
remappedFilters = remapFiltersToIds(filters.concat(rootFilters_1 || []), selectedFields);
|
|
377
|
-
remappedArrayFilters = remapFiltersToIds(filterArrays.concat(lookupFilters_1 || []), selectedFields);
|
|
378
|
-
postMatchAnd = [];
|
|
379
|
-
if (remappedFilters.length) {
|
|
380
|
-
postMatchAnd.push.apply(postMatchAnd, __spreadArray([], __read(remappedFilters), false));
|
|
381
|
-
}
|
|
382
|
-
if (remappedArrayFilters.length) {
|
|
383
|
-
postMatchAnd.push.apply(postMatchAnd, __spreadArray([], __read(remappedArrayFilters), false));
|
|
384
|
-
}
|
|
385
|
-
if (postMatchAnd.length) {
|
|
386
|
-
unionQuery_1.push({ $match: { $and: postMatchAnd } });
|
|
387
|
-
}
|
|
388
|
-
readPreference_1 = this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary';
|
|
389
|
-
queryResult_1 = {
|
|
390
|
-
count: 0,
|
|
391
|
-
results: [],
|
|
392
|
-
totals: {}
|
|
393
|
-
};
|
|
394
|
-
_c.label = 2;
|
|
395
|
-
case 2:
|
|
396
|
-
_c.trys.push([2, 4, , 5]);
|
|
397
|
-
return [4 /*yield*/, executeReportBuilderQuery(modelCollection, unionQuery_1, rootOptions, fieldsTotal, selectedFields, customFields, readPreference_1)];
|
|
398
|
-
case 3:
|
|
399
|
-
queryResult_1 = _c.sent();
|
|
400
|
-
return [3 /*break*/, 5];
|
|
401
|
-
case 4:
|
|
402
|
-
err_1 = _c.sent();
|
|
403
|
-
console.log(err_1);
|
|
404
|
-
return [3 /*break*/, 5];
|
|
405
|
-
case 5:
|
|
406
|
-
tmpRes_1 = [{
|
|
407
|
-
count: queryResult_1.count,
|
|
408
|
-
results: queryResult_1.results,
|
|
409
|
-
totals: queryResult_1.totals
|
|
410
|
-
}];
|
|
411
|
-
return [2 /*return*/, tmpRes_1];
|
|
412
|
-
case 6:
|
|
413
|
-
query_1 = [];
|
|
414
|
-
initialQueryMatchCondition_1 = {
|
|
415
|
-
$and: []
|
|
416
|
-
};
|
|
417
|
-
// selectedFields.filter(a => a.collection_name === rootCollectionName).forEach(field => {
|
|
418
|
-
// initialQueryMatchCondition['$and'].push({
|
|
419
|
-
// $and: [
|
|
420
|
-
// {[field.fieldPath.replace(/\.\$/g, '')]: {$exists: 1}},
|
|
421
|
-
// // {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: ''}},
|
|
422
|
-
// {[field.fieldPath.replace(/\.\$/g, '')]: {$ne: null}},
|
|
423
|
-
// ]
|
|
424
|
-
// });
|
|
425
|
-
// });
|
|
426
|
-
if (rootFilters_1.length) {
|
|
427
|
-
rootFilters_1.forEach(function (filter) { return initialQueryMatchCondition_1['$and'].push(filter); });
|
|
428
|
-
}
|
|
429
|
-
// Add filter to query
|
|
430
|
-
// if (filters.filter(a => (!a['$or'] && !Object.keys(a).some(b => b.includes('(Lookup'))) || (a['$or'] && !a['$or'].some(b => Object.keys(b).some(c => c.includes('(Lookup)'))))).length || selectedFields.filter(a => !a.fieldPath.includes('(Lookup')).length) {
|
|
431
|
-
if (initialQueryMatchCondition_1['$and'].length) {
|
|
432
|
-
query_1.push({
|
|
433
|
-
$match: initialQueryMatchCondition_1
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
// Add count
|
|
437
|
-
query_1.push({ $addFields: { count: { $sum: 1 } } });
|
|
438
|
-
sizes_1 = [];
|
|
439
|
-
filterArrayFields.filter(function (a) { return a.fieldPath; }).forEach(function (filterField) {
|
|
440
|
-
var fieldData = filterField.fieldPath.split('.$');
|
|
441
|
-
var fieldPath = '';
|
|
442
|
-
var _loop_2 = function (i) {
|
|
443
|
-
var _a, _b;
|
|
444
|
-
fieldPath += fieldData[i];
|
|
445
|
-
if (filterField.lookup_collection || fieldPath.split('.$')[fieldPath.split('.$').length - 1].includes('(Lookup')) {
|
|
446
|
-
(0, report_builder_unwinds_1.ensureLookupLocalKeyUnwinds)({
|
|
447
|
-
query: query_1,
|
|
448
|
-
sizes: sizes_1,
|
|
449
|
-
lookupLocalKey: filterField.lookup_local_key || '',
|
|
450
|
-
lookupAs: filterField.lookup_as || ''
|
|
451
|
-
});
|
|
452
|
-
var lookupAs_1 = filterField.lookup_as.replace(/\.\$/g, '');
|
|
453
|
-
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === lookupAs_1; })) {
|
|
454
|
-
query_1.push({ $lookup: {
|
|
455
|
-
from: filterField.lookup_collection,
|
|
456
|
-
localField: (0, report_builder_unwinds_1.normalizeLookupField)(filterField.lookup_local_key),
|
|
457
|
-
foreignField: (0, report_builder_unwinds_1.normalizeLookupField)(filterField.lookup_foreign_key),
|
|
458
|
-
as: lookupAs_1
|
|
459
|
-
} });
|
|
460
|
-
var lookupSizeKey = filterField.lookup_as.replace(/\.\$\./g, '_').replace(/\./g, '_');
|
|
461
|
-
sizes_1.push(lookupSizeKey);
|
|
462
|
-
var lookupSourceExpr = '$' + lookupAs_1;
|
|
463
|
-
query_1.push({ $addFields: (_a = {}, _a['size_' + lookupSizeKey] = { $size: { $cond: [{ $isArray: lookupSourceExpr }, lookupSourceExpr, []] } }, _a) });
|
|
464
|
-
var unwindPath = '$' + lookupAs_1;
|
|
465
|
-
query_1.push({ '$unwind': { path: unwindPath, preserveNullAndEmptyArrays: true } });
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath.replace(/\./g, '_')); })) {
|
|
470
|
-
sizes_1.push(fieldPath.replace(/\./g, '_'));
|
|
471
|
-
var sourceExpr = '$' + fieldPath;
|
|
472
|
-
query_1.push({ $addFields: (_b = {}, _b['size_' + fieldPath.replace(/\./g, '_')] = { $size: { $cond: [{ $isArray: sourceExpr }, sourceExpr, []] } }, _b) });
|
|
473
|
-
var unwindPath = '$' + fieldPath;
|
|
474
|
-
query_1.push({ '$unwind': { path: unwindPath, preserveNullAndEmptyArrays: true } });
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
479
|
-
_loop_2(i);
|
|
480
|
-
}
|
|
481
|
-
});
|
|
482
|
-
// Groups - Lookups / Sizes / Unwinds
|
|
483
|
-
groupsRow.forEach(function (row) {
|
|
484
|
-
var _a, _b, _c;
|
|
485
|
-
var rowField = (row && typeof row.field === 'string') ? row.field : '';
|
|
486
|
-
if (rowField.includes('$')) {
|
|
487
|
-
var fieldData = rowField.split('.$');
|
|
488
|
-
var fieldPath_1 = '';
|
|
489
|
-
var _loop_3 = function (i) {
|
|
490
|
-
var _d, _e;
|
|
491
|
-
fieldPath_1 += fieldData[i];
|
|
492
|
-
var lastSegment = fieldPath_1.split('.$')[fieldPath_1.split('.$').length - 1];
|
|
493
|
-
var hasLookup = !!((_a = row.treeItem) === null || _a === void 0 ? void 0 : _a.lookup_collection) || (lastSegment || '').includes('(Lookup');
|
|
494
|
-
if (hasLookup && ((_b = row.treeItem) === null || _b === void 0 ? void 0 : _b.lookup_collection) && ((_c = row.treeItem) === null || _c === void 0 ? void 0 : _c.lookup_as)) {
|
|
495
|
-
(0, report_builder_unwinds_1.ensureLookupLocalKeyUnwinds)({
|
|
496
|
-
query: query_1,
|
|
497
|
-
sizes: sizes_1,
|
|
498
|
-
lookupLocalKey: row.treeItem.lookup_local_key || '',
|
|
499
|
-
lookupAs: row.treeItem.lookup_as || ''
|
|
500
|
-
});
|
|
501
|
-
var lookupAsRaw = row.treeItem.lookup_as || '';
|
|
502
|
-
var lookupAs_2 = lookupAsRaw.replace(/\.\$/g, '');
|
|
503
|
-
if (!query_1.some(function (a) { return a.$lookup && a.$lookup.as === lookupAs_2; })) {
|
|
504
|
-
query_1.push({ $lookup: {
|
|
505
|
-
from: row.treeItem.lookup_collection,
|
|
506
|
-
localField: (0, report_builder_unwinds_1.normalizeLookupField)(row.treeItem.lookup_local_key || ''),
|
|
507
|
-
foreignField: (0, report_builder_unwinds_1.normalizeLookupField)(row.treeItem.lookup_foreign_key || ''),
|
|
508
|
-
as: lookupAs_2
|
|
509
|
-
} });
|
|
510
|
-
var sizeKey = lookupAsRaw.replace(/\.\$\./g, '_').replace(/\./g, '_');
|
|
511
|
-
sizes_1.push(sizeKey);
|
|
512
|
-
var sourceExpr = '$' + lookupAs_2;
|
|
513
|
-
query_1.push({ $addFields: (_d = {}, _d['size_' + sizeKey] = { $size: { $cond: [{ $isArray: sourceExpr }, sourceExpr, []] } }, _d) });
|
|
514
|
-
var unwindPath = '$' + lookupAs_2;
|
|
515
|
-
query_1.push({ '$unwind': { path: unwindPath, preserveNullAndEmptyArrays: true } });
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
else {
|
|
519
|
-
if (!query_1.some(function (a) { return a.$addFields && Object.keys(a.$addFields).includes('size_' + fieldPath_1.replace(/\.\$\./g, '.').replace(/\./g, '_')); })) {
|
|
520
|
-
var sizeKey = fieldPath_1.replace(/\.\$\./g, '.').replace(/\./g, '_');
|
|
521
|
-
sizes_1.push(sizeKey);
|
|
522
|
-
var sourceExpr = '$' + fieldPath_1.replace(/\.\$\./g, '.');
|
|
523
|
-
query_1.push({ $addFields: (_e = {}, _e['size_' + sizeKey] = { $size: { $cond: [{ $isArray: sourceExpr }, sourceExpr, []] } }, _e) });
|
|
524
|
-
var unwindPath = '$' + fieldPath_1.replace(/\.\$\./g, '.');
|
|
525
|
-
query_1.push({ '$unwind': { path: unwindPath, preserveNullAndEmptyArrays: true } });
|
|
526
|
-
}
|
|
527
|
-
}
|
|
528
|
-
fieldPath_1 += '.$';
|
|
529
|
-
};
|
|
530
|
-
for (var i = 0; i < fieldData.length - 1; i++) {
|
|
531
|
-
_loop_3(i);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
(0, report_builder_unwinds_1.applyLinkFieldUnwinds)({
|
|
536
|
-
query: query_1,
|
|
537
|
-
sizes: sizes_1,
|
|
538
|
-
fieldsLink: fieldsLink,
|
|
539
|
-
selectedFields: selectedFields,
|
|
540
|
-
filterArrayFields: filterArrayFields,
|
|
541
|
-
groupsRow: groupsRow
|
|
542
|
-
});
|
|
543
|
-
divFields_1 = { $addFields: {} };
|
|
544
|
-
fieldsTotal.filter(function (a) { return a.type === 'sum'; }).forEach(function (total) {
|
|
545
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
546
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
547
|
-
if (!fieldPath && field.leafValueType !== 'Count') {
|
|
548
|
-
return;
|
|
549
|
-
}
|
|
550
|
-
var multFields = [];
|
|
551
|
-
if (!fieldPath.includes('.$')) {
|
|
552
|
-
sizes_1.forEach(function (size) {
|
|
553
|
-
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
554
|
-
});
|
|
555
|
-
}
|
|
556
|
-
else {
|
|
557
|
-
sizes_1.filter(function (a) { return !fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
558
|
-
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
559
|
-
});
|
|
560
|
-
}
|
|
561
|
-
if (multFields.length) {
|
|
562
|
-
if (field.leafValueType === 'Count') {
|
|
563
|
-
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
564
|
-
$divide: ['$count', { $multiply: multFields }]
|
|
565
|
-
};
|
|
566
|
-
}
|
|
567
|
-
else {
|
|
568
|
-
divFields_1.$addFields[total.id + '_' + field.id] = {
|
|
569
|
-
$divide: [buildArrayAwareNumericFieldExpr(fieldPath), { $multiply: multFields }]
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
else {
|
|
574
|
-
if (field.leafValueType === 'Count') {
|
|
575
|
-
divFields_1.$addFields[total.id + '_' + field.id] = '$count';
|
|
576
|
-
}
|
|
577
|
-
else {
|
|
578
|
-
divFields_1.$addFields[total.id + '_' + field.id] = buildArrayAwareNumericFieldExpr(fieldPath);
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
});
|
|
582
|
-
});
|
|
583
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' && a.leafValueType === 'Sum'; }).forEach(function (field) {
|
|
584
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
585
|
-
if (!fieldPath) {
|
|
586
|
-
return;
|
|
587
|
-
}
|
|
588
|
-
var multFields = [];
|
|
589
|
-
sizes_1.filter(function (a) { return !fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !groupsRow.some(function (b) { return (b.field || '').replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
590
|
-
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
591
|
-
});
|
|
592
|
-
if (multFields.length) {
|
|
593
|
-
divFields_1.$addFields[fieldPath.replace(/\.\$/g, '')] = {
|
|
594
|
-
$divide: [buildArrayAwareNumericFieldExpr(fieldPath), { $multiply: multFields }]
|
|
595
|
-
};
|
|
596
|
-
}
|
|
597
|
-
});
|
|
598
|
-
selectedFields.filter(function (a) { return a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
599
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
600
|
-
if (!fieldPath) {
|
|
601
|
-
return;
|
|
602
|
-
}
|
|
603
|
-
var multFields = [];
|
|
604
|
-
sizes_1.filter(function (a) { return !fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) && !groupsRow.some(function (b) { return (b.field || '').replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !filterArrayFields.filter(function (a) { return a.fieldPath; }).some(function (b) { return b.fieldPath.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }) && !fieldsLink.some(function (b) { return b.field_first.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a) || b.field_second.replace(/\.\$\./g, '_').replace(/\./g, '_').includes(a); }); }).forEach(function (size) {
|
|
605
|
-
multFields.push({ $cond: { if: { $gt: ['$size_' + size, 0] }, then: '$size_' + size, else: 1 } });
|
|
606
|
-
});
|
|
607
|
-
if (multFields.length) {
|
|
608
|
-
divFields_1.$addFields['count_' + fieldPath.replace(/\.\$/g, '')] = {
|
|
609
|
-
$divide: ['$count', { $multiply: multFields }]
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
else {
|
|
613
|
-
if (reportType !== 'Dated' && sizes_1.filter(function (a) { return fieldPath.replace(/\.\$\./g, '_').includes(a); }).length) {
|
|
614
|
-
sizes_1.filter(function (a) { return fieldPath.replace(/\.\$\./g, '_').includes(a); }).forEach(function (size) {
|
|
615
|
-
divFields_1.$addFields['count_' + fieldPath.replace(/\.\$/g, '')] = '$size_' + size;
|
|
616
|
-
});
|
|
617
|
-
}
|
|
618
|
-
else {
|
|
619
|
-
divFields_1.$addFields['count_' + fieldPath.replace(/\.\$/g, '')] = '$count';
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
});
|
|
623
|
-
fieldsTotal.filter(function (a) { return a.type === 'avg'; }).forEach(function (total) {
|
|
624
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
625
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
626
|
-
if (!fieldPath && field.leafValueType !== 'Count') {
|
|
627
|
-
return;
|
|
628
|
-
}
|
|
629
|
-
divFields_1.$addFields[total.id + '_' + field.id] = buildArrayAwareNumericFieldExpr(fieldPath);
|
|
630
|
-
});
|
|
631
|
-
});
|
|
632
|
-
if (Object.keys(divFields_1.$addFields).length > 0) {
|
|
633
|
-
query_1.push(divFields_1);
|
|
634
|
-
}
|
|
635
|
-
fieldsLink.filter(function (a) { return a.field_first && a.field_second; }).forEach(function (link) {
|
|
636
|
-
var _a, _b;
|
|
637
|
-
query_1.push({ $addFields: (_a = {}, _a[link.id] = { $cmp: ['$' + link.field_first.replace(/\.\$/g, ''), '$' + link.field_second.replace(/\.\$/g, '')] }, _a) });
|
|
638
|
-
query_1.push({ $match: (_b = {}, _b[link.id] = 0, _b) });
|
|
639
|
-
});
|
|
640
|
-
customFields.forEach(function (cust) {
|
|
641
|
-
cust.operations.filter(function (a) { return a.operation && !a.fields.some(function (b) { return (b.field === null || b.field === '') && b.value === null; }); }).forEach(function (operation, opIndex) {
|
|
642
|
-
var _a, _b;
|
|
643
|
-
var custFieldGroup = {};
|
|
644
|
-
if (operation.operation === 'divide') {
|
|
645
|
-
var condCheck_1 = [];
|
|
646
|
-
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
647
|
-
if (field.field) {
|
|
648
|
-
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), 0] });
|
|
649
|
-
condCheck_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
650
|
-
}
|
|
651
|
-
else {
|
|
652
|
-
condCheck_1.push({ $eq: [field.value, 0] });
|
|
653
|
-
condCheck_1.push({ $eq: [field.value, null] });
|
|
654
|
-
}
|
|
655
|
-
});
|
|
656
|
-
if (opIndex > 0) {
|
|
657
|
-
condCheck_1.push({ $eq: ['$' + cust.selFieldId, 0] });
|
|
658
|
-
condCheck_1.push({ $eq: ['$' + cust.selFieldId, null] });
|
|
659
|
-
}
|
|
660
|
-
var tmpOperationFields_1 = [];
|
|
661
|
-
if (opIndex > 0) {
|
|
662
|
-
tmpOperationFields_1.push('$' + cust.selFieldId);
|
|
663
|
-
}
|
|
664
|
-
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
665
|
-
if (field.field) {
|
|
666
|
-
tmpOperationFields_1.push('$' + field.field.replace(/\.\$/g, ''));
|
|
667
|
-
}
|
|
668
|
-
else {
|
|
669
|
-
tmpOperationFields_1.push(field.value);
|
|
670
|
-
}
|
|
671
|
-
});
|
|
672
|
-
custFieldGroup[cust.selFieldId] = {
|
|
673
|
-
$cond: { if: { $or: condCheck_1 }, then: 0, else: (_a = {}, _a['$' + operation.operation] = tmpOperationFields_1, _a) }
|
|
674
|
-
};
|
|
675
|
-
}
|
|
676
|
-
else {
|
|
677
|
-
custFieldGroup[cust.selFieldId] = (_b = {},
|
|
678
|
-
_b['$' + operation.operation] = [],
|
|
679
|
-
_b);
|
|
680
|
-
if (opIndex > 0) {
|
|
681
|
-
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $eq: ['$' + cust.selFieldId, null] }, then: 0, else: '$' + cust.selFieldId } });
|
|
682
|
-
}
|
|
683
|
-
var condOr_1 = [];
|
|
684
|
-
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
685
|
-
if (field.field) {
|
|
686
|
-
condOr_1.push({ $eq: ['$' + field.field.replace(/\.\$/g, ''), null] });
|
|
687
|
-
}
|
|
688
|
-
else {
|
|
689
|
-
condOr_1.push({ $eq: [field.value, null] });
|
|
690
|
-
}
|
|
691
|
-
});
|
|
692
|
-
operation.fields.filter(function (a) { return a.field || a.value !== null; }).forEach(function (field) {
|
|
693
|
-
if (field.field) {
|
|
694
|
-
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: '$' + field.field.replace(/\.\$/g, '') } });
|
|
695
|
-
}
|
|
696
|
-
else {
|
|
697
|
-
custFieldGroup[cust.selFieldId]['$' + operation.operation].push({ $cond: { if: { $or: condOr_1 }, then: 0, else: field.value } });
|
|
698
|
-
}
|
|
699
|
-
});
|
|
700
|
-
}
|
|
701
|
-
query_1.push({ $addFields: custFieldGroup });
|
|
702
|
-
});
|
|
703
|
-
});
|
|
704
|
-
fieldsTotal.forEach(function (total) {
|
|
705
|
-
customFields.forEach(function (field) {
|
|
706
|
-
var _a;
|
|
707
|
-
query_1.push({ $addFields: (_a = {}, _a[total.id + '_' + field.selFieldId] = '$' + field.selFieldId, _a) });
|
|
708
|
-
});
|
|
709
|
-
});
|
|
710
|
-
queryMatchConditionLookup_1 = {
|
|
711
|
-
$and: []
|
|
712
|
-
};
|
|
713
|
-
if (lookupFilters_1.length) {
|
|
714
|
-
lookupFilters_1.forEach(function (filter) { return queryMatchConditionLookup_1['$and'].push(filter); });
|
|
715
|
-
}
|
|
716
|
-
filterArrays.forEach(function (filter) {
|
|
717
|
-
queryMatchConditionLookup_1['$and'].push(filter);
|
|
718
|
-
});
|
|
719
|
-
if (queryMatchConditionLookup_1.$and.length) {
|
|
720
|
-
query_1.push({ $match: queryMatchConditionLookup_1 });
|
|
721
|
-
}
|
|
722
|
-
queryGroup_1 = {
|
|
723
|
-
_id: {}
|
|
724
|
-
};
|
|
725
|
-
if (groupsRow.length || !displayType || displayType === 'grouped') {
|
|
726
|
-
if (!groupsRow.length) {
|
|
727
|
-
queryGroup_1._id = '$_id';
|
|
728
|
-
}
|
|
729
|
-
else {
|
|
730
|
-
if (rootOptions.sort) {
|
|
731
|
-
groupedSorts_1 = {};
|
|
732
|
-
Object.keys(rootOptions.sort).forEach(function (sortField) {
|
|
733
|
-
var selField = selectedFields.find(function (a) { return a.id === sortField; });
|
|
734
|
-
if (selField) {
|
|
735
|
-
var sortPath = (selField && typeof selField.fieldPath === 'string') ? selField.fieldPath.replace(/\.\$/g, '') : '';
|
|
736
|
-
if (sortPath) {
|
|
737
|
-
groupedSorts_1[sortPath] = rootOptions.sort[sortField];
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
if (Object.keys(groupedSorts_1).length > 0) {
|
|
742
|
-
query_1.push({
|
|
743
|
-
$sort: groupedSorts_1
|
|
744
|
-
});
|
|
745
|
-
}
|
|
746
|
-
}
|
|
747
|
-
}
|
|
748
|
-
if (groupsRow.length && date_field && date_interval) {
|
|
749
|
-
dateFieldPath = (typeof date_field === 'string') ? date_field.replace(/\.\$/g, '') : '';
|
|
750
|
-
if (dateFieldPath) {
|
|
751
|
-
dateFieldExpr = '$' + dateFieldPath;
|
|
752
|
-
utcHourExpr = { '$hour': { date: dateFieldExpr, timezone: 'UTC' } };
|
|
753
|
-
utcMinuteExpr = { '$minute': { date: dateFieldExpr, timezone: 'UTC' } };
|
|
754
|
-
utcSecondExpr = { '$second': { date: dateFieldExpr, timezone: 'UTC' } };
|
|
755
|
-
utcDayExpr = { '$dayOfMonth': { date: dateFieldExpr, timezone: 'UTC' } };
|
|
756
|
-
tzDayExpr = { '$dayOfMonth': { date: dateFieldExpr, timezone: reportBuilderTimezone } };
|
|
757
|
-
useUtcForDateOnlyExpr = {
|
|
758
|
-
$and: [
|
|
759
|
-
{ $eq: [utcHourExpr, 0] },
|
|
760
|
-
{ $eq: [utcMinuteExpr, 0] },
|
|
761
|
-
{ $eq: [utcSecondExpr, 0] },
|
|
762
|
-
{ $ne: [utcDayExpr, tzDayExpr] }
|
|
763
|
-
]
|
|
764
|
-
};
|
|
765
|
-
groupingTimezoneExpr = { $cond: [useUtcForDateOnlyExpr, 'UTC', reportBuilderTimezone] };
|
|
766
|
-
if (date_interval === 'Seconds') {
|
|
767
|
-
queryGroup_1._id['second'] = { '$second': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
768
|
-
queryGroup_1._id['minute'] = { '$minute': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
769
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
770
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
771
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
772
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
773
|
-
}
|
|
774
|
-
else if (date_interval === 'Minutes') {
|
|
775
|
-
queryGroup_1._id['minute'] = { '$minute': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
776
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
777
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
778
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
779
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
780
|
-
}
|
|
781
|
-
else if (date_interval === 'Hours') {
|
|
782
|
-
queryGroup_1._id['hour'] = { '$hour': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
783
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
784
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
785
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
786
|
-
}
|
|
787
|
-
else if (date_interval === 'Daily') {
|
|
788
|
-
queryGroup_1._id['day'] = { '$dayOfMonth': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
789
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
790
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
791
|
-
}
|
|
792
|
-
else if (date_interval === 'Weekly') {
|
|
793
|
-
queryGroup_1._id['week'] = { '$isoWeek': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
794
|
-
queryGroup_1._id['year'] = { '$isoWeekYear': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
795
|
-
}
|
|
796
|
-
else if (date_interval === 'Monthly') {
|
|
797
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
798
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
799
|
-
}
|
|
800
|
-
else if (date_interval === 'Quarterly') {
|
|
801
|
-
queryGroup_1._id['month'] = { '$month': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
802
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
803
|
-
}
|
|
804
|
-
else if (date_interval === 'Yearly') {
|
|
805
|
-
queryGroup_1._id['year'] = { '$year': { 'date': dateFieldExpr, 'timezone': groupingTimezoneExpr } };
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
groupsRow.forEach(function (row) {
|
|
810
|
-
var rowField = (row && typeof row.field === 'string') ? row.field : '';
|
|
811
|
-
if (!rowField || !(row === null || row === void 0 ? void 0 : row.id)) {
|
|
812
|
-
return;
|
|
813
|
-
}
|
|
814
|
-
queryGroup_1._id[row.id] = '$' + rowField.replace(/\.\$/g, '');
|
|
815
|
-
});
|
|
816
|
-
selectedFields.forEach(function (field) {
|
|
817
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
818
|
-
if (!fieldPath) {
|
|
819
|
-
if (field.leafValueType === 'Count') {
|
|
820
|
-
queryGroup_1[field.id] = { '$sum': 1 };
|
|
821
|
-
}
|
|
822
|
-
return;
|
|
823
|
-
}
|
|
824
|
-
if (field.leafValueType === 'Average') {
|
|
825
|
-
queryGroup_1[field.id] = { '$avg': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
826
|
-
}
|
|
827
|
-
else if (field.leafValueType === 'Sum') {
|
|
828
|
-
queryGroup_1[field.id] = { '$sum': buildArrayAwareNumericFieldExpr(fieldPath) };
|
|
829
|
-
}
|
|
830
|
-
else if (field.leafValueType === 'Count') {
|
|
831
|
-
queryGroup_1[field.id] = { '$sum': '$count_' + fieldPath.replace(/\.\$/g, '') };
|
|
832
|
-
}
|
|
833
|
-
else if (field.leafValueType === 'Minimum') {
|
|
834
|
-
queryGroup_1[field.id] = { '$min': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
835
|
-
}
|
|
836
|
-
else if (field.leafValueType === 'Maximum') {
|
|
837
|
-
queryGroup_1[field.id] = { '$max': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
838
|
-
}
|
|
839
|
-
else if (field.leafValueType === 'First') {
|
|
840
|
-
queryGroup_1[field.id] = { '$first': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
841
|
-
}
|
|
842
|
-
else if (field.leafValueType === 'Last') {
|
|
843
|
-
queryGroup_1[field.id] = { '$last': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
844
|
-
}
|
|
845
|
-
else if (field.leafValueType === 'Unique') {
|
|
846
|
-
queryGroup_1[field.id] = { '$addToSet': '$' + fieldPath.replace(/\.\$/g, '') };
|
|
847
|
-
}
|
|
848
|
-
else {
|
|
849
|
-
queryGroup_1[field.id] = { '$push': { $ifNull: ['$' + fieldPath.replace(/\.\$/g, ''), null] } };
|
|
850
|
-
}
|
|
851
|
-
});
|
|
852
|
-
customFields.forEach(function (cust) {
|
|
853
|
-
if (cust.leafValueType === 'Average') {
|
|
854
|
-
queryGroup_1[cust.selFieldId] = { '$avg': '$' + cust.selFieldId };
|
|
855
|
-
}
|
|
856
|
-
else if (cust.leafValueType === 'Sum') {
|
|
857
|
-
queryGroup_1[cust.selFieldId] = { '$sum': '$' + cust.selFieldId };
|
|
858
|
-
}
|
|
859
|
-
else if (cust.leafValueType === 'Count') {
|
|
860
|
-
if (reportType === 'Dated') {
|
|
861
|
-
queryGroup_1[cust.selFieldId] = { '$sum': '$count_' + cust.selFieldId };
|
|
862
|
-
}
|
|
863
|
-
else {
|
|
864
|
-
queryGroup_1[cust.selFieldId] = { '$push': '$count_' + cust.selFieldId };
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
else if (cust.leafValueType === 'Minimum') {
|
|
868
|
-
queryGroup_1[cust.selFieldId] = { '$min': '$' + cust.selFieldId };
|
|
869
|
-
}
|
|
870
|
-
else if (cust.leafValueType === 'Maximum') {
|
|
871
|
-
queryGroup_1[cust.selFieldId] = { '$max': '$' + cust.selFieldId };
|
|
872
|
-
}
|
|
873
|
-
else if (cust.leafValueType === 'First') {
|
|
874
|
-
queryGroup_1[cust.selFieldId] = { '$first': '$' + cust.selFieldId };
|
|
875
|
-
}
|
|
876
|
-
else if (cust.leafValueType === 'Last') {
|
|
877
|
-
queryGroup_1[cust.selFieldId] = { '$last': '$' + cust.selFieldId };
|
|
878
|
-
}
|
|
879
|
-
else if (cust.leafValueType === 'Unique') {
|
|
880
|
-
queryGroup_1[cust.selFieldId] = { '$addToSet': '$' + cust.selFieldId };
|
|
881
|
-
}
|
|
882
|
-
else {
|
|
883
|
-
queryGroup_1[cust.selFieldId] = { '$push': { $ifNull: ['$' + cust.selFieldId, null] } };
|
|
884
|
-
}
|
|
885
|
-
});
|
|
886
|
-
// Totals
|
|
887
|
-
if (fieldsTotal.length) {
|
|
888
|
-
fieldsTotal.forEach(function (total) {
|
|
889
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
890
|
-
var _a;
|
|
891
|
-
queryGroup_1[total.id + '_' + field.id] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.id, _a);
|
|
892
|
-
});
|
|
893
|
-
customFields.forEach(function (field) {
|
|
894
|
-
var _a;
|
|
895
|
-
queryGroup_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
896
|
-
});
|
|
897
|
-
});
|
|
898
|
-
}
|
|
899
|
-
query_1.push({ $group: queryGroup_1 });
|
|
900
|
-
}
|
|
901
|
-
else {
|
|
902
|
-
queryProjection_1 = {
|
|
903
|
-
_id: 1
|
|
904
|
-
};
|
|
905
|
-
selectedFields.forEach(function (field) {
|
|
906
|
-
var fieldPath = (field && typeof field.fieldPath === 'string') ? field.fieldPath : '';
|
|
907
|
-
if (!fieldPath && field.leafValueType !== 'Count') {
|
|
908
|
-
return;
|
|
909
|
-
}
|
|
910
|
-
if (field.leafValueType === 'Average') {
|
|
911
|
-
queryProjection_1[field.id] = buildArrayAwareAverageFieldExpr(fieldPath);
|
|
912
|
-
}
|
|
913
|
-
else if (field.leafValueType === 'Sum') {
|
|
914
|
-
queryProjection_1[field.id] = buildArrayAwareNumericFieldExpr(fieldPath);
|
|
915
|
-
}
|
|
916
|
-
else if (field.leafValueType === 'Count') {
|
|
917
|
-
queryProjection_1[field.id] = { $sum: 1 };
|
|
918
|
-
}
|
|
919
|
-
else if (field.leafValueType === 'Minimum') {
|
|
920
|
-
queryProjection_1[field.id] = { $min: '$' + fieldPath.replace(/\.\$/g, '') };
|
|
921
|
-
}
|
|
922
|
-
else if (field.leafValueType === 'Maximum') {
|
|
923
|
-
queryProjection_1[field.id] = { $max: '$' + fieldPath.replace(/\.\$/g, '') };
|
|
924
|
-
}
|
|
925
|
-
else {
|
|
926
|
-
queryProjection_1[field.id] = '$' + fieldPath.replace(/\.\$/g, '');
|
|
927
|
-
}
|
|
928
|
-
});
|
|
929
|
-
customFields.forEach(function (cust) {
|
|
930
|
-
if (cust === 'Average') {
|
|
931
|
-
queryProjection_1[cust.selFieldId] = { $avg: '$' + cust.selFieldId };
|
|
932
|
-
}
|
|
933
|
-
else if (cust === 'Sum') {
|
|
934
|
-
queryProjection_1[cust.selFieldId] = { $sum: '$' + cust.selFieldId };
|
|
935
|
-
}
|
|
936
|
-
else if (cust === 'Count') {
|
|
937
|
-
queryProjection_1[cust.selFieldId] = { $sum: 1 };
|
|
938
|
-
}
|
|
939
|
-
else if (cust === 'Minimum') {
|
|
940
|
-
queryProjection_1[cust.selFieldId] = { $min: '$' + cust.selFieldId };
|
|
941
|
-
}
|
|
942
|
-
else if (cust === 'Maximum') {
|
|
943
|
-
queryProjection_1[cust.selFieldId] = { $max: '$' + cust.selFieldId };
|
|
944
|
-
}
|
|
945
|
-
else {
|
|
946
|
-
queryProjection_1[cust.selFieldId] = '$' + cust.selFieldId;
|
|
947
|
-
}
|
|
948
|
-
});
|
|
949
|
-
//Totals
|
|
950
|
-
if (fieldsTotal.length && (reportType === 'List' || reportType === 'Dated')) {
|
|
951
|
-
fieldsTotal.forEach(function (total) {
|
|
952
|
-
selectedFields.filter(function (a) { return a.fieldType === 'Number' || a.leafValueType === 'Count'; }).forEach(function (field) {
|
|
953
|
-
var _a;
|
|
954
|
-
var totalFieldPath = total.id + '_' + field.id;
|
|
955
|
-
if (total.type === 'sum') {
|
|
956
|
-
queryProjection_1[totalFieldPath] = buildArrayAwareNumericFieldExpr(totalFieldPath);
|
|
957
|
-
}
|
|
958
|
-
else if (total.type === 'avg') {
|
|
959
|
-
queryProjection_1[totalFieldPath] = buildArrayAwareAverageFieldExpr(totalFieldPath);
|
|
960
|
-
}
|
|
961
|
-
else {
|
|
962
|
-
queryProjection_1[totalFieldPath] = (_a = {}, _a['$' + total.type] = '$' + totalFieldPath, _a);
|
|
963
|
-
}
|
|
964
|
-
});
|
|
965
|
-
customFields.forEach(function (field) {
|
|
966
|
-
var _a;
|
|
967
|
-
queryProjection_1[total.id + '_' + field.selFieldId] = (_a = {}, _a['$' + total.type] = '$' + total.id + '_' + field.selFieldId, _a);
|
|
968
|
-
});
|
|
969
|
-
});
|
|
970
|
-
}
|
|
971
|
-
query_1.push({ $project: queryProjection_1 });
|
|
972
|
-
}
|
|
973
|
-
// SORT
|
|
974
|
-
if (rootOptions.sort) {
|
|
975
|
-
appendSafeSort(query_1, rootOptions.sort, selectedFields, customFields);
|
|
976
|
-
}
|
|
977
|
-
if (reportType === 'Group' && groupsRow.length > 1) {
|
|
978
|
-
_loop_1 = function (i) {
|
|
979
|
-
var _d;
|
|
980
|
-
var projQuery = { _id: 1 };
|
|
981
|
-
projQuery[groupsRow[i].id] = {
|
|
982
|
-
_id: (_d = {}, _d[groupsRow[i].id] = '$_id.' + groupsRow[i].id, _d)
|
|
983
|
-
};
|
|
984
|
-
if (i === groupsRow.length - 1) {
|
|
985
|
-
selectedFields.forEach(function (field) {
|
|
986
|
-
projQuery[groupsRow[i].id][field.id] = '$' + field.id;
|
|
987
|
-
});
|
|
988
|
-
customFields.forEach(function (field) {
|
|
989
|
-
projQuery[groupsRow[i].id][field.selFieldId] = '$' + field.selFieldId;
|
|
990
|
-
});
|
|
991
|
-
}
|
|
992
|
-
else {
|
|
993
|
-
projQuery[groupsRow[i].id][groupsRow[i + 1].id] = '$' + groupsRow[i + 1].id;
|
|
994
|
-
}
|
|
995
|
-
fieldsTotal.forEach(function (totField) {
|
|
996
|
-
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
997
|
-
projQuery[totField.id + '_' + selField.id] = 1;
|
|
998
|
-
projQuery[groupsRow[i].id][totField.id + '_' + selField.id] = '$' + totField.id + '_' + selField.id;
|
|
999
|
-
});
|
|
1000
|
-
customFields.forEach(function (field) {
|
|
1001
|
-
projQuery[groupsRow[i].id][totField.id + '_' + field.selFieldId] = '$' + totField.id + '_' + field.selFieldId;
|
|
1002
|
-
});
|
|
1003
|
-
});
|
|
1004
|
-
query_1.push({ $project: projQuery });
|
|
1005
|
-
var grQuery = {
|
|
1006
|
-
_id: {}
|
|
1007
|
-
};
|
|
1008
|
-
for (var j = 0; j < i; j++) {
|
|
1009
|
-
grQuery._id[groupsRow[j].id] = '$_id.' + groupsRow[j].id;
|
|
1010
|
-
}
|
|
1011
|
-
grQuery[groupsRow[i].id] = {
|
|
1012
|
-
$push: '$' + groupsRow[i].id
|
|
1013
|
-
};
|
|
1014
|
-
fieldsTotal.forEach(function (totField) {
|
|
1015
|
-
selectedFields.filter(function (b) { return b.fieldType === 'Number' || b.leafValueType === 'Count'; }).forEach(function (selField) {
|
|
1016
|
-
var _a;
|
|
1017
|
-
grQuery[totField.id + '_' + selField.id] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + selField.id, _a);
|
|
1018
|
-
});
|
|
1019
|
-
customFields.forEach(function (field) {
|
|
1020
|
-
var _a;
|
|
1021
|
-
grQuery[totField.id + '_' + field.selFieldId] = (_a = {}, _a['$' + totField.type] = '$' + totField.id + '_' + field.selFieldId, _a);
|
|
1022
|
-
});
|
|
1023
|
-
});
|
|
1024
|
-
query_1.push({ $group: grQuery });
|
|
1025
|
-
if (rootOptions.sort) {
|
|
1026
|
-
var sortKeys_1 = Object.keys(rootOptions.sort);
|
|
1027
|
-
var sort_1 = {};
|
|
1028
|
-
var groupString_1 = '';
|
|
1029
|
-
groupsRow.forEach(function (row, groupIndex) {
|
|
1030
|
-
if (groupIndex > 0) {
|
|
1031
|
-
groupString_1 += 'gr_' + (groupIndex + 1) + '.';
|
|
1032
|
-
}
|
|
1033
|
-
if (sortKeys_1.includes('_id.gr_' + (groupIndex + 1))) {
|
|
1034
|
-
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = rootOptions.sort['_id.gr_' + (groupIndex + 1)];
|
|
1035
|
-
}
|
|
1036
|
-
else {
|
|
1037
|
-
sort_1[groupString_1 + '_id.gr_' + (groupIndex + 1)] = 1;
|
|
1038
|
-
}
|
|
1039
|
-
});
|
|
1040
|
-
sortKeys_1.filter(function (a) { return !a.startsWith('_id.gr_'); }).forEach(function (key) {
|
|
1041
|
-
sort_1[groupString_1 + key] = rootOptions.sort[key];
|
|
1042
|
-
});
|
|
1043
|
-
appendSafeSort(query_1, sort_1, selectedFields, customFields);
|
|
1044
|
-
}
|
|
1045
|
-
};
|
|
1046
|
-
for (i = groupsRow.length - 1; i >= 1; i--) {
|
|
1047
|
-
_loop_1(i);
|
|
1048
|
-
}
|
|
1049
|
-
}
|
|
1050
|
-
if (this.serverConfig['ROOT_URL'] === 'http://localhost:4200') {
|
|
1051
|
-
console.log('_____________ query __________');
|
|
1052
|
-
console.log(JSON.stringify(query_1, null, 2));
|
|
1053
|
-
}
|
|
1054
|
-
readPreference = this.serverConfig['ROOT_URL'] !== 'http://localhost:4200' ? 'secondary' : 'primary';
|
|
1055
|
-
queryResult = {
|
|
1056
|
-
count: 0,
|
|
1057
|
-
results: [],
|
|
1058
|
-
totals: {}
|
|
1059
|
-
};
|
|
1060
|
-
_c.label = 7;
|
|
1061
|
-
case 7:
|
|
1062
|
-
_c.trys.push([7, 9, , 10]);
|
|
1063
|
-
return [4 /*yield*/, executeReportBuilderQuery(modelCollection, query_1, rootOptions, fieldsTotal, selectedFields, customFields, readPreference)];
|
|
1064
|
-
case 8:
|
|
1065
|
-
queryResult = _c.sent();
|
|
1066
|
-
return [3 /*break*/, 10];
|
|
1067
|
-
case 9:
|
|
1068
|
-
err_2 = _c.sent();
|
|
1069
|
-
console.log(err_2);
|
|
1070
|
-
return [3 /*break*/, 10];
|
|
1071
|
-
case 10:
|
|
1072
|
-
tmpRes = [{
|
|
1073
|
-
count: queryResult.count,
|
|
1074
|
-
results: queryResult.results,
|
|
1075
|
-
totals: queryResult.totals
|
|
1076
|
-
}];
|
|
1077
|
-
return [2 /*return*/, tmpRes];
|
|
1078
|
-
}
|
|
1079
|
-
});
|
|
1080
|
-
});
|
|
1081
|
-
},
|
|
1082
|
-
workerTaskWeight: 2
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
}
|
|
1086
|
-
function coerceReportBuilderNumeric(value) {
|
|
1087
|
-
if (Array.isArray(value)) {
|
|
1088
|
-
return value.map(function (v) { return coerceReportBuilderNumeric(v); }).reduce(function (a, b) { return a + b; }, 0);
|
|
1089
|
-
}
|
|
1090
|
-
var num = typeof value === 'number' ? value : (value !== null && value !== undefined ? Number(value) : 0);
|
|
1091
|
-
return isNaN(num) ? 0 : num;
|
|
1092
|
-
}
|
|
1093
|
-
function buildReportBuilderTotalsFieldKeySets(fieldsTotal, selectedFields, customFields) {
|
|
1094
|
-
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
1095
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1096
|
-
if (customFields === void 0) { customFields = []; }
|
|
1097
|
-
var numericSelectedFields = selectedFields.filter(function (field) { return (field === null || field === void 0 ? void 0 : field.fieldType) === 'Number' || (field === null || field === void 0 ? void 0 : field.leafValueType) === 'Count'; });
|
|
1098
|
-
var sumKeys = new Set();
|
|
1099
|
-
var avgKeys = new Set();
|
|
1100
|
-
fieldsTotal.forEach(function (totalField) {
|
|
1101
|
-
numericSelectedFields.forEach(function (selectedField) {
|
|
1102
|
-
var key = "".concat(totalField.id, "_").concat(selectedField.id);
|
|
1103
|
-
if (!key) {
|
|
1104
|
-
return;
|
|
1105
|
-
}
|
|
1106
|
-
if (totalField.type === 'sum') {
|
|
1107
|
-
sumKeys.add(key);
|
|
1108
|
-
}
|
|
1109
|
-
else if (totalField.type === 'avg') {
|
|
1110
|
-
avgKeys.add(key);
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
customFields.forEach(function (customField) {
|
|
1114
|
-
var customId = customField === null || customField === void 0 ? void 0 : customField.selFieldId;
|
|
1115
|
-
if (!customId) {
|
|
1116
|
-
return;
|
|
1117
|
-
}
|
|
1118
|
-
var key = "".concat(totalField.id, "_").concat(customId);
|
|
1119
|
-
if (totalField.type === 'sum') {
|
|
1120
|
-
sumKeys.add(key);
|
|
1121
|
-
}
|
|
1122
|
-
else if (totalField.type === 'avg') {
|
|
1123
|
-
avgKeys.add(key);
|
|
1124
|
-
}
|
|
1125
|
-
});
|
|
1126
|
-
});
|
|
1127
|
-
return { sumKeys: sumKeys, avgKeys: avgKeys };
|
|
1128
|
-
}
|
|
1129
|
-
function buildReportBuilderTotalsFromSums(fieldsTotal, selectedFields, customFields, sumValues, count) {
|
|
1130
|
-
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
1131
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1132
|
-
if (customFields === void 0) { customFields = []; }
|
|
1133
|
-
if (sumValues === void 0) { sumValues = {}; }
|
|
1134
|
-
if (count === void 0) { count = 0; }
|
|
1135
|
-
var numericSelectedFields = selectedFields.filter(function (field) { return (field === null || field === void 0 ? void 0 : field.fieldType) === 'Number' || (field === null || field === void 0 ? void 0 : field.leafValueType) === 'Count'; });
|
|
1136
|
-
var totals = {};
|
|
1137
|
-
fieldsTotal.forEach(function (totalField) {
|
|
1138
|
-
numericSelectedFields.forEach(function (selectedField) {
|
|
1139
|
-
var key = "".concat(totalField.id, "_").concat(selectedField.id);
|
|
1140
|
-
var sum = coerceReportBuilderNumeric(sumValues[key]);
|
|
1141
|
-
if (totalField.type === 'sum') {
|
|
1142
|
-
totals[key] = sum;
|
|
1143
|
-
}
|
|
1144
|
-
else if (totalField.type === 'avg') {
|
|
1145
|
-
totals[key] = count ? (0, common_1.round)(sum / count) : 0;
|
|
1146
|
-
}
|
|
1147
|
-
});
|
|
1148
|
-
customFields.forEach(function (customField) {
|
|
1149
|
-
var customId = customField === null || customField === void 0 ? void 0 : customField.selFieldId;
|
|
1150
|
-
if (!customId) {
|
|
1151
|
-
return;
|
|
1152
|
-
}
|
|
1153
|
-
var key = "".concat(totalField.id, "_").concat(customId);
|
|
1154
|
-
var sum = coerceReportBuilderNumeric(sumValues[key]);
|
|
1155
|
-
if (totalField.type === 'sum') {
|
|
1156
|
-
totals[key] = sum;
|
|
1157
|
-
}
|
|
1158
|
-
else if (totalField.type === 'avg') {
|
|
1159
|
-
totals[key] = count ? (0, common_1.round)(sum / count) : 0;
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
});
|
|
1163
|
-
return totals;
|
|
1164
|
-
}
|
|
1165
|
-
function buildReportBuilderNumericSumExpr(fieldKey) {
|
|
1166
|
-
var fieldExpr = '$' + fieldKey;
|
|
1167
|
-
return {
|
|
1168
|
-
$cond: [
|
|
1169
|
-
{ $isArray: fieldExpr },
|
|
1170
|
-
{
|
|
1171
|
-
$reduce: {
|
|
1172
|
-
input: fieldExpr,
|
|
1173
|
-
initialValue: 0,
|
|
1174
|
-
in: {
|
|
1175
|
-
$add: [
|
|
1176
|
-
'$$value',
|
|
1177
|
-
{ $convert: { input: '$$this', to: 'double', onError: 0, onNull: 0 } }
|
|
1178
|
-
]
|
|
1179
|
-
}
|
|
1180
|
-
}
|
|
1181
|
-
},
|
|
1182
|
-
{ $convert: { input: fieldExpr, to: 'double', onError: 0, onNull: 0 } }
|
|
1183
|
-
]
|
|
1184
|
-
};
|
|
1185
|
-
}
|
|
1186
|
-
function executeReportBuilderQuery(modelCollection_1, query_2, rootOptions_1) {
|
|
1187
|
-
return __awaiter(this, arguments, void 0, function (modelCollection, query, rootOptions, fieldsTotal, selectedFields, customFields, readPreference) {
|
|
1188
|
-
var aggregateOptions, _a, sumKeys, avgKeys, allTotalKeys, resultsFacet, facet, totalsGroup_1, facetedQuery, facetedResult, facetDoc, count, results_1, totalsDoc_1, sumValues_1, totals_1, fullResult, rows, sumValues, results, totals;
|
|
1189
|
-
var _b, _c, _d;
|
|
1190
|
-
if (fieldsTotal === void 0) { fieldsTotal = []; }
|
|
1191
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1192
|
-
if (customFields === void 0) { customFields = []; }
|
|
1193
|
-
if (readPreference === void 0) { readPreference = 'primary'; }
|
|
1194
|
-
return __generator(this, function (_e) {
|
|
1195
|
-
switch (_e.label) {
|
|
1196
|
-
case 0:
|
|
1197
|
-
aggregateOptions = {
|
|
1198
|
-
allowDiskUse: true,
|
|
1199
|
-
readPreference: readPreference
|
|
1200
|
-
};
|
|
1201
|
-
_a = buildReportBuilderTotalsFieldKeySets(fieldsTotal, selectedFields, customFields), sumKeys = _a.sumKeys, avgKeys = _a.avgKeys;
|
|
1202
|
-
allTotalKeys = new Set(__spreadArray(__spreadArray([], __read(sumKeys), false), __read(avgKeys), false));
|
|
1203
|
-
if (!((rootOptions === null || rootOptions === void 0 ? void 0 : rootOptions.limit) && rootOptions.limit > 0)) return [3 /*break*/, 2];
|
|
1204
|
-
resultsFacet = [];
|
|
1205
|
-
if (rootOptions.skip && rootOptions.skip > 0) {
|
|
1206
|
-
resultsFacet.push({ $skip: rootOptions.skip });
|
|
1207
|
-
}
|
|
1208
|
-
resultsFacet.push({ $limit: rootOptions.limit });
|
|
1209
|
-
facet = {
|
|
1210
|
-
results: resultsFacet,
|
|
1211
|
-
count: [{ $count: 'count' }],
|
|
1212
|
-
totals: []
|
|
1213
|
-
};
|
|
1214
|
-
if (allTotalKeys.size) {
|
|
1215
|
-
totalsGroup_1 = {
|
|
1216
|
-
_id: null,
|
|
1217
|
-
__count: { $sum: 1 }
|
|
1218
|
-
};
|
|
1219
|
-
Array.from(allTotalKeys).forEach(function (key) {
|
|
1220
|
-
totalsGroup_1[key] = { $sum: buildReportBuilderNumericSumExpr(key) };
|
|
1221
|
-
});
|
|
1222
|
-
facet.totals = [
|
|
1223
|
-
{ $group: totalsGroup_1 }
|
|
1224
|
-
];
|
|
1225
|
-
}
|
|
1226
|
-
facetedQuery = query.concat([
|
|
1227
|
-
{ $facet: facet }
|
|
1228
|
-
]);
|
|
1229
|
-
return [4 /*yield*/, modelCollection.aggregate(facetedQuery, aggregateOptions, true)];
|
|
1230
|
-
case 1:
|
|
1231
|
-
facetedResult = _e.sent();
|
|
1232
|
-
facetDoc = Array.isArray(facetedResult) && facetedResult.length ? facetedResult[0] : {};
|
|
1233
|
-
count = ((_c = (_b = facetDoc === null || facetDoc === void 0 ? void 0 : facetDoc.count) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.count) || 0;
|
|
1234
|
-
results_1 = Array.isArray(facetDoc === null || facetDoc === void 0 ? void 0 : facetDoc.results) ? facetDoc.results : [];
|
|
1235
|
-
totalsDoc_1 = ((_d = facetDoc === null || facetDoc === void 0 ? void 0 : facetDoc.totals) === null || _d === void 0 ? void 0 : _d[0]) || {};
|
|
1236
|
-
sumValues_1 = {};
|
|
1237
|
-
Array.from(allTotalKeys).forEach(function (key) {
|
|
1238
|
-
sumValues_1[key] = coerceReportBuilderNumeric(totalsDoc_1[key]);
|
|
1239
|
-
});
|
|
1240
|
-
totals_1 = buildReportBuilderTotalsFromSums(fieldsTotal, selectedFields, customFields, sumValues_1, count);
|
|
1241
|
-
return [2 /*return*/, { count: count, results: results_1, totals: totals_1 }];
|
|
1242
|
-
case 2: return [4 /*yield*/, modelCollection.aggregate(query, aggregateOptions, true)];
|
|
1243
|
-
case 3:
|
|
1244
|
-
fullResult = _e.sent();
|
|
1245
|
-
rows = Array.isArray(fullResult) ? fullResult : [];
|
|
1246
|
-
sumValues = {};
|
|
1247
|
-
Array.from(allTotalKeys).forEach(function (key) {
|
|
1248
|
-
sumValues[key] = rows.map(function (row) { return coerceReportBuilderNumeric(row ? row[key] : 0); }).reduce(function (a, b) { return a + b; }, 0);
|
|
1249
|
-
});
|
|
1250
|
-
results = rows;
|
|
1251
|
-
if ((rootOptions === null || rootOptions === void 0 ? void 0 : rootOptions.skip) && rootOptions.skip > 0) {
|
|
1252
|
-
results = results.slice(rootOptions.skip);
|
|
1253
|
-
}
|
|
1254
|
-
if ((rootOptions === null || rootOptions === void 0 ? void 0 : rootOptions.limit) && rootOptions.limit > 0) {
|
|
1255
|
-
results = results.slice(0, rootOptions.limit);
|
|
1256
|
-
}
|
|
1257
|
-
totals = buildReportBuilderTotalsFromSums(fieldsTotal, selectedFields, customFields, sumValues, rows.length);
|
|
1258
|
-
return [2 /*return*/, {
|
|
1259
|
-
count: rows.length,
|
|
1260
|
-
results: results,
|
|
1261
|
-
totals: totals
|
|
1262
|
-
}];
|
|
1263
|
-
}
|
|
1264
|
-
});
|
|
1265
|
-
});
|
|
1266
|
-
}
|
|
1267
|
-
function buildCollectionTree(collectionName, lookupNode) {
|
|
1268
|
-
var _a;
|
|
1269
|
-
var lookupSchemaData = (0, schema_report_builder_1.getReportLookupSchemas)(collectionName).sort(function (a, b) { return a.collection_name.localeCompare(b.collection_name); });
|
|
1270
|
-
var lookupSchemaTree = ((_a = lookupSchemaData.find(function (a) { return a.is_root === true; })) === null || _a === void 0 ? void 0 : _a.tree) || {};
|
|
1271
|
-
var treeItems = (0, schema_report_builder_1.buildTree)(collectionName, lookupSchemaTree, lookupNode);
|
|
1272
|
-
attachLookupChildren(treeItems, lookupSchemaData, lookupSchemaTree);
|
|
1273
|
-
return { isLeaf: false, children: treeItems };
|
|
1274
|
-
}
|
|
1275
|
-
function attachLookupChildren(treeItems, lookupSchemaData, lookupSchemaTree) {
|
|
1276
|
-
Object.keys(lookupSchemaTree || {}).filter(function (a) { return a.endsWith('(Lookup)'); }).forEach(function (lookup) {
|
|
1277
|
-
var field = findFieldByPath(treeItems, lookup);
|
|
1278
|
-
if (field) {
|
|
1279
|
-
var lookupTree = lookupSchemaData.find(function (a) { return a.collection_name === lookupSchemaTree[lookup].lookup_collection; });
|
|
1280
|
-
if (lookupTree) {
|
|
1281
|
-
var childTree = (0, schema_report_builder_1.buildTree)(lookupSchemaTree[lookup].lookup_collection, lookupTree.tree, field);
|
|
1282
|
-
attachLookupChildren(childTree, lookupSchemaData, lookupTree.tree);
|
|
1283
|
-
field.children = childTree;
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
});
|
|
1287
|
-
}
|
|
1288
|
-
function findFieldByPath(treeItems, lookupPath) {
|
|
1289
|
-
var fieldPath = lookupPath.split('.');
|
|
1290
|
-
var field = null;
|
|
1291
|
-
fieldPath.forEach(function (path) {
|
|
1292
|
-
if (!field) {
|
|
1293
|
-
field = treeItems.find(function (a) { return a.fieldName === path; });
|
|
1294
|
-
}
|
|
1295
|
-
else if (field.children) {
|
|
1296
|
-
field = field.children.find(function (a) { return a.fieldName === path; });
|
|
1297
|
-
}
|
|
1298
|
-
});
|
|
1299
|
-
return field;
|
|
1300
|
-
}
|
|
1301
|
-
function buildJoinLookupNode(collection_root, join, alias) {
|
|
1302
|
-
return {
|
|
1303
|
-
collection_name: collection_root,
|
|
1304
|
-
columnName: alias,
|
|
1305
|
-
fieldName: alias,
|
|
1306
|
-
fieldType: 'Lookup',
|
|
1307
|
-
fieldTypeName: 'Lookup',
|
|
1308
|
-
distinctFieldValues: [],
|
|
1309
|
-
fieldPath: alias,
|
|
1310
|
-
fieldPathName: alias,
|
|
1311
|
-
path: alias,
|
|
1312
|
-
lookup_collection: join.collection,
|
|
1313
|
-
lookup_local_key: join.local_key,
|
|
1314
|
-
lookup_foreign_key: join.foreign_key,
|
|
1315
|
-
lookup_as: alias,
|
|
1316
|
-
text: alias,
|
|
1317
|
-
value: alias,
|
|
1318
|
-
isLeaf: false,
|
|
1319
|
-
isActive: false,
|
|
1320
|
-
isSelected: false,
|
|
1321
|
-
is_join: false,
|
|
1322
|
-
depth: 0,
|
|
1323
|
-
leafValueType: '',
|
|
1324
|
-
leafFormatType: '',
|
|
1325
|
-
children: []
|
|
1326
|
-
};
|
|
1327
|
-
}
|
|
1328
|
-
function buildJoinAlias(join, joinIndex) {
|
|
1329
|
-
if (join.alias && join.alias.trim()) {
|
|
1330
|
-
return join.alias.trim();
|
|
1331
|
-
}
|
|
1332
|
-
var joinName = (0, common_1.toTitleCase)(join.collection.replace(/\_/g, ' ').replace(/-/g, ' '));
|
|
1333
|
-
var joinPath = (0, common_1.toTitleCase)(join.local_key.replace(/\.\$\./g, ' -> ').replace(/\./g, ' -> ').replace(/\_/g, ' '));
|
|
1334
|
-
return "".concat(joinName, " (").concat(joinPath || 'Join', ") (Lookup ").concat(joinIndex + 1, ")");
|
|
1335
|
-
}
|
|
1336
|
-
function buildArrayAwareNumericFieldExpr(fieldPath) {
|
|
1337
|
-
var normalizedFieldPath = (fieldPath || '').replace(/\.\$/g, '');
|
|
1338
|
-
if (!normalizedFieldPath) {
|
|
1339
|
-
return 0;
|
|
1340
|
-
}
|
|
1341
|
-
var fieldExpr = '$' + normalizedFieldPath;
|
|
1342
|
-
return {
|
|
1343
|
-
$cond: [
|
|
1344
|
-
{ $isArray: fieldExpr },
|
|
1345
|
-
{ $sum: { $ifNull: [fieldExpr, []] } },
|
|
1346
|
-
{ $ifNull: [fieldExpr, 0] }
|
|
1347
|
-
]
|
|
1348
|
-
};
|
|
1349
|
-
}
|
|
1350
|
-
function buildArrayAwareAverageFieldExpr(fieldPath) {
|
|
1351
|
-
var normalizedFieldPath = (fieldPath || '').replace(/\.\$/g, '');
|
|
1352
|
-
if (!normalizedFieldPath) {
|
|
1353
|
-
return 0;
|
|
1354
|
-
}
|
|
1355
|
-
var fieldExpr = '$' + normalizedFieldPath;
|
|
1356
|
-
return {
|
|
1357
|
-
$cond: [
|
|
1358
|
-
{ $isArray: fieldExpr },
|
|
1359
|
-
{
|
|
1360
|
-
$cond: [
|
|
1361
|
-
{ $gt: [{ $size: { $ifNull: [fieldExpr, []] } }, 0] },
|
|
1362
|
-
{ $avg: { $ifNull: [fieldExpr, []] } },
|
|
1363
|
-
0
|
|
1364
|
-
]
|
|
1365
|
-
},
|
|
1366
|
-
{ $ifNull: [fieldExpr, 0] }
|
|
1367
|
-
]
|
|
1368
|
-
};
|
|
1369
|
-
}
|
|
1370
|
-
function appendSafeSort(query, sortSpec, selectedFields, customFields) {
|
|
1371
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1372
|
-
if (customFields === void 0) { customFields = []; }
|
|
1373
|
-
if (!sortSpec || !Object.keys(sortSpec).length) {
|
|
1374
|
-
return;
|
|
1375
|
-
}
|
|
1376
|
-
var safeAddFields = {};
|
|
1377
|
-
var safeSort = {};
|
|
1378
|
-
Object.keys(sortSpec).forEach(function (key) {
|
|
1379
|
-
if (key.startsWith('_id.')) {
|
|
1380
|
-
safeSort[key] = sortSpec[key];
|
|
1381
|
-
return;
|
|
1382
|
-
}
|
|
1383
|
-
if (isArrayLikeField(key, selectedFields, customFields)) {
|
|
1384
|
-
var safeKey = 'sort_' + key.replace(/\./g, '_');
|
|
1385
|
-
safeAddFields[safeKey] = {
|
|
1386
|
-
$cond: [
|
|
1387
|
-
{ $isArray: '$' + key },
|
|
1388
|
-
{ $size: { $ifNull: ['$' + key, []] } },
|
|
1389
|
-
'$' + key
|
|
1390
|
-
]
|
|
1391
|
-
};
|
|
1392
|
-
safeSort[safeKey] = sortSpec[key];
|
|
1393
|
-
}
|
|
1394
|
-
else {
|
|
1395
|
-
safeSort[key] = sortSpec[key];
|
|
1396
|
-
}
|
|
1397
|
-
});
|
|
1398
|
-
if (Object.keys(safeAddFields).length) {
|
|
1399
|
-
query.push({ $addFields: safeAddFields });
|
|
1400
|
-
}
|
|
1401
|
-
if (Object.keys(safeSort).length) {
|
|
1402
|
-
query.push({ $sort: safeSort });
|
|
1403
|
-
}
|
|
1404
|
-
}
|
|
1405
|
-
function isArrayLikeField(sortKey, selectedFields, customFields) {
|
|
1406
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1407
|
-
if (customFields === void 0) { customFields = []; }
|
|
1408
|
-
var field = selectedFields.find(function (a) { return a.id === sortKey; });
|
|
1409
|
-
var custom = customFields.find(function (a) { return a.selFieldId === sortKey; });
|
|
1410
|
-
var leafValueType = field ? field.leafValueType : (custom ? custom.leafValueType : '');
|
|
1411
|
-
return leafValueType !== 'Average' &&
|
|
1412
|
-
leafValueType !== 'Sum' &&
|
|
1413
|
-
leafValueType !== 'Count' &&
|
|
1414
|
-
leafValueType !== 'Minimum' &&
|
|
1415
|
-
leafValueType !== 'Maximum' &&
|
|
1416
|
-
leafValueType !== 'First' &&
|
|
1417
|
-
leafValueType !== 'Last' &&
|
|
1418
|
-
leafValueType !== 'Unique';
|
|
1419
|
-
}
|
|
1420
|
-
function collectLookupAliases(selectedFields, filterArrayFields, groupsRow) {
|
|
1421
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1422
|
-
if (filterArrayFields === void 0) { filterArrayFields = []; }
|
|
1423
|
-
if (groupsRow === void 0) { groupsRow = []; }
|
|
1424
|
-
var aliases = new Set();
|
|
1425
|
-
var addAlias = function (alias) {
|
|
1426
|
-
var normalized = normalizeLookupAlias(alias);
|
|
1427
|
-
if (normalized) {
|
|
1428
|
-
aliases.add(normalized);
|
|
1429
|
-
}
|
|
1430
|
-
};
|
|
1431
|
-
(selectedFields || []).forEach(function (field) {
|
|
1432
|
-
if (field && (field.lookup_collection || (field.fieldPath && field.fieldPath.includes('(Lookup')))) {
|
|
1433
|
-
addAlias(field.lookup_as || extractLookupAlias(field.fieldPath));
|
|
1434
|
-
}
|
|
1435
|
-
});
|
|
1436
|
-
(filterArrayFields || []).forEach(function (field) {
|
|
1437
|
-
if (field && (field.lookup_collection || (field.fieldPath && field.fieldPath.includes('(Lookup')))) {
|
|
1438
|
-
addAlias(field.lookup_as || extractLookupAlias(field.fieldPath));
|
|
1439
|
-
}
|
|
1440
|
-
});
|
|
1441
|
-
(groupsRow || []).forEach(function (group) {
|
|
1442
|
-
if ((group === null || group === void 0 ? void 0 : group.treeItem) && (group.treeItem.lookup_collection || (group.treeItem.fieldPath && group.treeItem.fieldPath.includes('(Lookup')))) {
|
|
1443
|
-
addAlias(group.treeItem.lookup_as || extractLookupAlias(group.treeItem.fieldPath));
|
|
1444
|
-
}
|
|
1445
|
-
});
|
|
1446
|
-
return aliases;
|
|
1447
|
-
}
|
|
1448
|
-
function splitFiltersByLookup(filters, lookupAliases) {
|
|
1449
|
-
if (filters === void 0) { filters = []; }
|
|
1450
|
-
if (lookupAliases === void 0) { lookupAliases = new Set(); }
|
|
1451
|
-
var rootFilters = [];
|
|
1452
|
-
var lookupFilters = [];
|
|
1453
|
-
(filters || []).forEach(function (filter) {
|
|
1454
|
-
var summary = summarizeFilterTargets(filter, lookupAliases);
|
|
1455
|
-
if (summary.hasLookup) {
|
|
1456
|
-
// If the filter mixes root + lookup, keep it together in lookupFilters so it stays a single $match/$or
|
|
1457
|
-
lookupFilters.push(filter);
|
|
1458
|
-
}
|
|
1459
|
-
else {
|
|
1460
|
-
rootFilters.push(filter);
|
|
1461
|
-
}
|
|
1462
|
-
});
|
|
1463
|
-
return { rootFilters: rootFilters, lookupFilters: lookupFilters };
|
|
1464
|
-
}
|
|
1465
|
-
function summarizeFilterTargets(filter, lookupAliases) {
|
|
1466
|
-
var result = { hasLookup: false, hasRoot: false };
|
|
1467
|
-
if (!filter || typeof filter !== 'object') {
|
|
1468
|
-
return result;
|
|
1469
|
-
}
|
|
1470
|
-
Object.keys(filter).forEach(function (key) {
|
|
1471
|
-
if (key === '$or' || key === '$and') {
|
|
1472
|
-
var branch = filter[key];
|
|
1473
|
-
if (Array.isArray(branch)) {
|
|
1474
|
-
branch.forEach(function (child) {
|
|
1475
|
-
var childSummary = summarizeFilterTargets(child, lookupAliases);
|
|
1476
|
-
result.hasLookup = result.hasLookup || childSummary.hasLookup;
|
|
1477
|
-
result.hasRoot = result.hasRoot || childSummary.hasRoot;
|
|
1478
|
-
});
|
|
1479
|
-
}
|
|
1480
|
-
}
|
|
1481
|
-
else {
|
|
1482
|
-
var isLookup = isLookupPath(key, lookupAliases);
|
|
1483
|
-
if (isLookup) {
|
|
1484
|
-
result.hasLookup = true;
|
|
1485
|
-
}
|
|
1486
|
-
else {
|
|
1487
|
-
result.hasRoot = true;
|
|
1488
|
-
}
|
|
1489
|
-
}
|
|
1490
|
-
});
|
|
1491
|
-
return result;
|
|
1492
|
-
}
|
|
1493
|
-
function isLookupPath(path, lookupAliases) {
|
|
1494
|
-
if (!path) {
|
|
1495
|
-
return false;
|
|
1496
|
-
}
|
|
1497
|
-
var normalizedPath = path.replace(/\.\$/g, '');
|
|
1498
|
-
if (normalizedPath.includes('(Lookup')) {
|
|
1499
|
-
return true;
|
|
1500
|
-
}
|
|
1501
|
-
var rootKey = normalizedPath.split('.')[0];
|
|
1502
|
-
return lookupAliases.has(rootKey);
|
|
1503
|
-
}
|
|
1504
|
-
function extractLookupAlias(path) {
|
|
1505
|
-
if (!path || !path.includes('(Lookup')) {
|
|
1506
|
-
return '';
|
|
1507
|
-
}
|
|
1508
|
-
return path.replace(/\.\$/g, '').split('.')[0];
|
|
1509
|
-
}
|
|
1510
|
-
function normalizeLookupAlias(alias) {
|
|
1511
|
-
return (alias || '').replace(/\.\$/g, '').trim();
|
|
1512
|
-
}
|
|
1513
|
-
function collectRootDatePaths(collectionName) {
|
|
1514
|
-
var out = new Set();
|
|
1515
|
-
var collection = resolveio_server_app_1.ResolveIOServer.getMongoManager().collection(collectionName);
|
|
1516
|
-
var schema = (collection === null || collection === void 0 ? void 0 : collection.rbSchema) || {};
|
|
1517
|
-
Object.keys(schema).forEach(function (path) {
|
|
1518
|
-
var _a;
|
|
1519
|
-
if (((_a = schema[path]) === null || _a === void 0 ? void 0 : _a.rbType) === 'Date') {
|
|
1520
|
-
out.add(path.replace(/\.\$/g, ''));
|
|
1521
|
-
}
|
|
1522
|
-
});
|
|
1523
|
-
return out;
|
|
1524
|
-
}
|
|
1525
|
-
function coerceDateFilters(filters, datePaths) {
|
|
1526
|
-
if (filters === void 0) { filters = []; }
|
|
1527
|
-
var coerceDateValue = function (value) {
|
|
1528
|
-
if (value instanceof Date) {
|
|
1529
|
-
return value;
|
|
1530
|
-
}
|
|
1531
|
-
if (Array.isArray(value)) {
|
|
1532
|
-
return value.map(coerceDateValue);
|
|
1533
|
-
}
|
|
1534
|
-
if (typeof value === 'string' || typeof value === 'number') {
|
|
1535
|
-
var parsed = new Date(value);
|
|
1536
|
-
if (!isNaN(parsed.getTime())) {
|
|
1537
|
-
return parsed;
|
|
1538
|
-
}
|
|
1539
|
-
}
|
|
1540
|
-
return value;
|
|
1541
|
-
};
|
|
1542
|
-
var coerceFilterObject = function (obj) {
|
|
1543
|
-
if (!obj || typeof obj !== 'object') {
|
|
1544
|
-
return obj;
|
|
1545
|
-
}
|
|
1546
|
-
if (Array.isArray(obj)) {
|
|
1547
|
-
obj.forEach(coerceFilterObject);
|
|
1548
|
-
return obj;
|
|
1549
|
-
}
|
|
1550
|
-
if (obj.$or) {
|
|
1551
|
-
obj.$or = obj.$or.map(coerceFilterObject).filter(Boolean);
|
|
1552
|
-
return obj;
|
|
1553
|
-
}
|
|
1554
|
-
if (obj.$and) {
|
|
1555
|
-
obj.$and = obj.$and.map(coerceFilterObject).filter(Boolean);
|
|
1556
|
-
return obj;
|
|
1557
|
-
}
|
|
1558
|
-
Object.keys(obj).forEach(function (key) {
|
|
1559
|
-
if (key.startsWith('$')) {
|
|
1560
|
-
return;
|
|
1561
|
-
}
|
|
1562
|
-
var normalizedKey = key.replace(/\.\$/g, '');
|
|
1563
|
-
if (!datePaths.has(normalizedKey)) {
|
|
1564
|
-
return;
|
|
1565
|
-
}
|
|
1566
|
-
var value = obj[key];
|
|
1567
|
-
if (value && typeof value === 'object' && !Array.isArray(value) && !(value instanceof Date)) {
|
|
1568
|
-
Object.keys(value).forEach(function (op) {
|
|
1569
|
-
if (op.startsWith('$')) {
|
|
1570
|
-
value[op] = coerceDateValue(value[op]);
|
|
1571
|
-
}
|
|
1572
|
-
});
|
|
1573
|
-
}
|
|
1574
|
-
else {
|
|
1575
|
-
obj[key] = coerceDateValue(value);
|
|
1576
|
-
}
|
|
1577
|
-
});
|
|
1578
|
-
return obj;
|
|
1579
|
-
};
|
|
1580
|
-
(filters || []).forEach(coerceFilterObject);
|
|
1581
|
-
}
|
|
1582
|
-
// Helpers to support union-based joins (collection_joins without local/foreign key)
|
|
1583
|
-
function stripAliasFromPath(path, alias) {
|
|
1584
|
-
if (!path) {
|
|
1585
|
-
return path;
|
|
1586
|
-
}
|
|
1587
|
-
var cleanAlias = alias.replace(/\.\$/g, '');
|
|
1588
|
-
var cleanPath = path.replace(/\.\$/g, '');
|
|
1589
|
-
if (cleanPath.startsWith(cleanAlias + '.')) {
|
|
1590
|
-
return cleanPath.substring(cleanAlias.length + 1);
|
|
1591
|
-
}
|
|
1592
|
-
return cleanPath;
|
|
1593
|
-
}
|
|
1594
|
-
function buildCollectionPipeline(collectionName, alias, selectedFields, filters, filterArrays, isRoot) {
|
|
1595
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1596
|
-
if (filters === void 0) { filters = []; }
|
|
1597
|
-
if (filterArrays === void 0) { filterArrays = []; }
|
|
1598
|
-
if (isRoot === void 0) { isRoot = false; }
|
|
1599
|
-
var pipeline = [];
|
|
1600
|
-
var matchClauses = [];
|
|
1601
|
-
var matchArrayClauses = [];
|
|
1602
|
-
var targetAlias = isRoot ? '' : alias.replace(/\.\$/g, '');
|
|
1603
|
-
var mapFilterForCollection = function (filterObj, toArray) {
|
|
1604
|
-
if (!filterObj || typeof filterObj !== 'object') {
|
|
1605
|
-
return;
|
|
1606
|
-
}
|
|
1607
|
-
var mapped = mapFilterPaths(filterObj, targetAlias, isRoot);
|
|
1608
|
-
if (mapped) {
|
|
1609
|
-
(toArray ? matchArrayClauses : matchClauses).push(mapped);
|
|
1610
|
-
}
|
|
1611
|
-
};
|
|
1612
|
-
(filters || []).forEach(function (f) { return mapFilterForCollection(f, false); });
|
|
1613
|
-
(filterArrays || []).forEach(function (f) { return mapFilterForCollection(f, true); });
|
|
1614
|
-
if (matchClauses.length || matchArrayClauses.length) {
|
|
1615
|
-
var match = { $and: __spreadArray(__spreadArray([], __read(matchClauses), false), __read(matchArrayClauses), false) };
|
|
1616
|
-
pipeline.push({ $match: match });
|
|
1617
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
1618
|
-
console.info('RB debug: collection pipeline match', {
|
|
1619
|
-
collection: collectionName,
|
|
1620
|
-
alias: targetAlias || collectionName,
|
|
1621
|
-
matchJson: JSON.stringify(match, null, 2)
|
|
1622
|
-
});
|
|
1623
|
-
}
|
|
1624
|
-
}
|
|
1625
|
-
// Projection mapping selected fields for this collection
|
|
1626
|
-
var projection = { _id: 1, __rb_collection: targetAlias || collectionName };
|
|
1627
|
-
(selectedFields || [])
|
|
1628
|
-
.filter(function (f) { return isFieldForCollection(f, collectionName, targetAlias); })
|
|
1629
|
-
.forEach(function (f) {
|
|
1630
|
-
var mappedPath = stripAliasFromPath(f.fieldPath || '', targetAlias || f.lookup_as || '');
|
|
1631
|
-
if (f.leafValueType === 'Average') {
|
|
1632
|
-
projection[f.id] = buildArrayAwareAverageFieldExpr(mappedPath);
|
|
1633
|
-
}
|
|
1634
|
-
else if (f.leafValueType === 'Sum') {
|
|
1635
|
-
projection[f.id] = buildArrayAwareNumericFieldExpr(mappedPath);
|
|
1636
|
-
}
|
|
1637
|
-
else if (f.leafValueType === 'Count') {
|
|
1638
|
-
projection[f.id] = { $sum: 1 };
|
|
1639
|
-
}
|
|
1640
|
-
else if (f.leafValueType === 'Minimum') {
|
|
1641
|
-
projection[f.id] = { $min: '$' + mappedPath };
|
|
1642
|
-
}
|
|
1643
|
-
else if (f.leafValueType === 'Maximum') {
|
|
1644
|
-
projection[f.id] = { $max: '$' + mappedPath };
|
|
1645
|
-
}
|
|
1646
|
-
else {
|
|
1647
|
-
projection[f.id] = '$' + mappedPath;
|
|
1648
|
-
}
|
|
1649
|
-
});
|
|
1650
|
-
pipeline.push({ $project: projection });
|
|
1651
|
-
return pipeline;
|
|
1652
|
-
}
|
|
1653
|
-
function isFieldForCollection(field, collectionName, alias) {
|
|
1654
|
-
if (!field) {
|
|
1655
|
-
return false;
|
|
1656
|
-
}
|
|
1657
|
-
// Root collection check
|
|
1658
|
-
if (!alias) {
|
|
1659
|
-
return field.collection_name === collectionName && (!field.lookup_collection || field.lookup_collection === '');
|
|
1660
|
-
}
|
|
1661
|
-
// Joined collection check
|
|
1662
|
-
return field.lookup_collection === collectionName || (field.lookup_as && field.lookup_as.replace(/\.\$/g, '') === alias);
|
|
1663
|
-
}
|
|
1664
|
-
function mapFilterPaths(filter, alias, isRoot) {
|
|
1665
|
-
if (!filter || typeof filter !== 'object') {
|
|
1666
|
-
return null;
|
|
1667
|
-
}
|
|
1668
|
-
if (Array.isArray(filter)) {
|
|
1669
|
-
return filter.map(function (f) { return mapFilterPaths(f, alias, isRoot); });
|
|
1670
|
-
}
|
|
1671
|
-
if (filter.$or) {
|
|
1672
|
-
var mapped = filter.$or.map(function (f) { return mapFilterPaths(f, alias, isRoot); }).filter(Boolean);
|
|
1673
|
-
return mapped.length ? { $or: mapped } : null;
|
|
1674
|
-
}
|
|
1675
|
-
if (filter.$and) {
|
|
1676
|
-
var mapped = filter.$and.map(function (f) { return mapFilterPaths(f, alias, isRoot); }).filter(Boolean);
|
|
1677
|
-
return mapped.length ? { $and: mapped } : null;
|
|
1678
|
-
}
|
|
1679
|
-
var out = {};
|
|
1680
|
-
Object.keys(filter).forEach(function (key) {
|
|
1681
|
-
var cleanKey = key.replace(/\.\$/g, '');
|
|
1682
|
-
if (!alias) {
|
|
1683
|
-
// root collection: ignore keys that start with a lookup alias
|
|
1684
|
-
if (cleanKey.includes('(Lookup')) {
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
|
-
if (lookupAliasMatches(cleanKey, alias)) {
|
|
1688
|
-
return;
|
|
1689
|
-
}
|
|
1690
|
-
out[cleanKey] = filter[key];
|
|
1691
|
-
}
|
|
1692
|
-
else {
|
|
1693
|
-
if (cleanKey.startsWith(alias + '.')) {
|
|
1694
|
-
out[cleanKey.substring(alias.length + 1)] = filter[key];
|
|
1695
|
-
}
|
|
1696
|
-
}
|
|
1697
|
-
});
|
|
1698
|
-
return Object.keys(out).length ? out : null;
|
|
1699
|
-
}
|
|
1700
|
-
function lookupAliasMatches(path, alias) {
|
|
1701
|
-
if (!path || !alias) {
|
|
1702
|
-
return false;
|
|
1703
|
-
}
|
|
1704
|
-
return path.startsWith(alias + '.') || path === alias;
|
|
1705
|
-
}
|
|
1706
|
-
function buildLayoutSortSpec(sortSpec, selectedFields) {
|
|
1707
|
-
if (sortSpec === void 0) { sortSpec = {}; }
|
|
1708
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1709
|
-
var outSort = __assign({}, sortSpec);
|
|
1710
|
-
var addFields = {};
|
|
1711
|
-
Object.keys(sortSpec || {}).forEach(function (key) {
|
|
1712
|
-
if (!key.startsWith('layout_col_')) {
|
|
1713
|
-
return;
|
|
1714
|
-
}
|
|
1715
|
-
var normalized = key.replace(/^layout_col_/, '');
|
|
1716
|
-
var parts = normalized.split('_');
|
|
1717
|
-
var idx = parseInt(parts[parts.length - 1], 10);
|
|
1718
|
-
if (isNaN(idx)) {
|
|
1719
|
-
return;
|
|
1720
|
-
}
|
|
1721
|
-
var layoutFields = (selectedFields || []).filter(function (f) { return typeof (f === null || f === void 0 ? void 0 : f.layoutColumnIndex) !== 'undefined' && f.layoutColumnIndex === idx; }).map(function (f) { return f.id; }).filter(Boolean);
|
|
1722
|
-
if (!layoutFields.length) {
|
|
1723
|
-
return;
|
|
1724
|
-
}
|
|
1725
|
-
// Build nested $ifNull chain to coalesce across layout column targets
|
|
1726
|
-
var coalesce = '';
|
|
1727
|
-
for (var i = layoutFields.length - 1; i >= 0; i--) {
|
|
1728
|
-
var fieldPath = '$' + layoutFields[i];
|
|
1729
|
-
if (i === layoutFields.length - 1) {
|
|
1730
|
-
coalesce = fieldPath;
|
|
1731
|
-
}
|
|
1732
|
-
else {
|
|
1733
|
-
coalesce = { $ifNull: [fieldPath, coalesce] };
|
|
1734
|
-
}
|
|
1735
|
-
}
|
|
1736
|
-
var sortKey = 'sort_' + key;
|
|
1737
|
-
addFields[sortKey] = coalesce;
|
|
1738
|
-
delete outSort[key];
|
|
1739
|
-
outSort[sortKey] = sortSpec[key];
|
|
1740
|
-
});
|
|
1741
|
-
return { sortSpec: outSort, addFields: addFields };
|
|
1742
|
-
}
|
|
1743
|
-
function remapFiltersToIds(filters, selectedFields) {
|
|
1744
|
-
if (filters === void 0) { filters = []; }
|
|
1745
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1746
|
-
var byPath = new Map();
|
|
1747
|
-
var layoutMap = new Map();
|
|
1748
|
-
(selectedFields || []).forEach(function (f) {
|
|
1749
|
-
if ((f === null || f === void 0 ? void 0 : f.fieldPath) && (f === null || f === void 0 ? void 0 : f.id)) {
|
|
1750
|
-
byPath.set(f.fieldPath.replace(/\.\$/g, ''), f.id);
|
|
1751
|
-
}
|
|
1752
|
-
if (typeof (f === null || f === void 0 ? void 0 : f.layoutColumnIndex) !== 'undefined') {
|
|
1753
|
-
var arr = layoutMap.get(f.layoutColumnIndex) || [];
|
|
1754
|
-
arr.push(f.id);
|
|
1755
|
-
layoutMap.set(f.layoutColumnIndex, arr);
|
|
1756
|
-
}
|
|
1757
|
-
});
|
|
1758
|
-
var remapObj = function (obj) {
|
|
1759
|
-
if (!obj || typeof obj !== 'object') {
|
|
1760
|
-
return obj;
|
|
1761
|
-
}
|
|
1762
|
-
if (Array.isArray(obj)) {
|
|
1763
|
-
return obj.map(remapObj);
|
|
1764
|
-
}
|
|
1765
|
-
if (obj.$or) {
|
|
1766
|
-
var mapped = obj.$or.map(remapObj).filter(Boolean);
|
|
1767
|
-
return mapped.length ? { $or: mapped } : null;
|
|
1768
|
-
}
|
|
1769
|
-
if (obj.$and) {
|
|
1770
|
-
var mapped = obj.$and.map(remapObj).filter(Boolean);
|
|
1771
|
-
return mapped.length ? { $and: mapped } : null;
|
|
1772
|
-
}
|
|
1773
|
-
var out = {};
|
|
1774
|
-
Object.keys(obj).forEach(function (key) {
|
|
1775
|
-
var cleanKey = key.replace(/\.\$/g, '');
|
|
1776
|
-
if (cleanKey.startsWith('layout_col_')) {
|
|
1777
|
-
// map to all field ids in that layout column index
|
|
1778
|
-
var normalized = cleanKey.replace(/^layout_col_/, '');
|
|
1779
|
-
var parts = normalized.split('_');
|
|
1780
|
-
var idx = parseInt(parts[parts.length - 1], 10);
|
|
1781
|
-
var targets = layoutMap.get(idx) || [];
|
|
1782
|
-
if (targets.length) {
|
|
1783
|
-
var mappedVal_1 = remapObj(obj[key]);
|
|
1784
|
-
out.$or = targets.map(function (id) {
|
|
1785
|
-
var _a;
|
|
1786
|
-
return (_a = {}, _a[id] = mappedVal_1, _a);
|
|
1787
|
-
});
|
|
1788
|
-
return;
|
|
1789
|
-
}
|
|
1790
|
-
}
|
|
1791
|
-
var mappedKey = byPath.get(cleanKey) || cleanKey;
|
|
1792
|
-
out[mappedKey] = remapObj(obj[key]);
|
|
1793
|
-
});
|
|
1794
|
-
return Object.keys(out).length ? out : null;
|
|
1795
|
-
};
|
|
1796
|
-
return (filters || []).map(remapObj).filter(Boolean);
|
|
1797
|
-
}
|
|
1798
|
-
function expandLayoutColumnFilters(filters, selectedFields) {
|
|
1799
|
-
if (filters === void 0) { filters = []; }
|
|
1800
|
-
if (selectedFields === void 0) { selectedFields = []; }
|
|
1801
|
-
var layoutCache = {};
|
|
1802
|
-
var resolveLayoutPaths = function (layoutKey) {
|
|
1803
|
-
if (layoutCache[layoutKey]) {
|
|
1804
|
-
return layoutCache[layoutKey];
|
|
1805
|
-
}
|
|
1806
|
-
var paths = [];
|
|
1807
|
-
var normalized = (layoutKey || '').replace(/^layout_col_/, '');
|
|
1808
|
-
var parts = normalized.split('_');
|
|
1809
|
-
var idx = parseInt(parts[parts.length - 1], 10);
|
|
1810
|
-
if (!isNaN(idx)) {
|
|
1811
|
-
paths = (selectedFields || [])
|
|
1812
|
-
.filter(function (f) { return f && (f.layoutColumnIndex === idx || (f.id || '').includes("f_layout_".concat(idx, "_"))); })
|
|
1813
|
-
.map(function (f) { return f.fieldPath ? f.fieldPath.replace(/\.\$/g, '') : ''; })
|
|
1814
|
-
.filter(function (p) { return !!p; });
|
|
1815
|
-
}
|
|
1816
|
-
layoutCache[layoutKey] = paths;
|
|
1817
|
-
return paths;
|
|
1818
|
-
};
|
|
1819
|
-
var expandFilterObject = function (obj) {
|
|
1820
|
-
if (!obj || typeof obj !== 'object' || Array.isArray(obj)) {
|
|
1821
|
-
return obj;
|
|
1822
|
-
}
|
|
1823
|
-
if (obj.$or) {
|
|
1824
|
-
return { $or: obj.$or.map(expandFilterObject) };
|
|
1825
|
-
}
|
|
1826
|
-
if (obj.$and) {
|
|
1827
|
-
return { $and: obj.$and.map(expandFilterObject) };
|
|
1828
|
-
}
|
|
1829
|
-
var expanded = {};
|
|
1830
|
-
var replaced = false;
|
|
1831
|
-
Object.keys(obj).forEach(function (key) {
|
|
1832
|
-
var val = obj[key];
|
|
1833
|
-
if (key.startsWith('layout_col_')) {
|
|
1834
|
-
var paths = resolveLayoutPaths(key);
|
|
1835
|
-
if (paths.length) {
|
|
1836
|
-
replaced = true;
|
|
1837
|
-
expanded.$or = paths.map(function (path) {
|
|
1838
|
-
var _a;
|
|
1839
|
-
return (_a = {}, _a[path] = val, _a);
|
|
1840
|
-
});
|
|
1841
|
-
// Use console to trace layout filter expansion without requiring a logger on ResolveIOServer
|
|
1842
|
-
console.info('RB layout filter expansion', { layoutKey: key, paths: paths });
|
|
1843
|
-
}
|
|
1844
|
-
else {
|
|
1845
|
-
console.warn('RB layout filter expansion failed', { layoutKey: key, selectedFields: selectedFields });
|
|
1846
|
-
}
|
|
1847
|
-
}
|
|
1848
|
-
else {
|
|
1849
|
-
expanded[key] = val;
|
|
1850
|
-
}
|
|
1851
|
-
});
|
|
1852
|
-
return replaced ? expanded : obj;
|
|
1853
|
-
};
|
|
1854
|
-
return (filters || []).map(expandFilterObject);
|
|
1855
|
-
}
|
|
1856
|
-
function executeReportBuilderAi(payload, context) {
|
|
1857
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
1858
|
-
var input, prompt, isSuperAdmin, guardrailsEnabled, guardrail, reportTypeResolution, reportType, collectionRoot, collectionJoins, idDateField, dateInterval, collections, fieldLimit, resolvedFields, usedFallbackFields, derivedFields, trimmedFields, arraySummary, systemPrompt, userPrompt, codexModel, codexClient, runOptions, responseText, usage, parsed, allowMongoRead, mongoPayload, mongoReadResult, error_1, message, mongoContext, usage2, sanitizeContext, patch, summaryNotes, idClient;
|
|
1859
|
-
return __generator(this, function (_a) {
|
|
1860
|
-
switch (_a.label) {
|
|
1861
|
-
case 0:
|
|
1862
|
-
input = payload || {};
|
|
1863
|
-
prompt = normalizeOptionalString(input.prompt);
|
|
1864
|
-
if (!prompt) {
|
|
1865
|
-
throw new Error('Prompt is required.');
|
|
1866
|
-
}
|
|
1867
|
-
return [4 /*yield*/, resolveIsSuperAdmin(context === null || context === void 0 ? void 0 : context.id_user)];
|
|
1868
|
-
case 1:
|
|
1869
|
-
isSuperAdmin = _a.sent();
|
|
1870
|
-
guardrailsEnabled = input.guardrails !== false && !isSuperAdmin;
|
|
1871
|
-
if (guardrailsEnabled) {
|
|
1872
|
-
guardrail = evaluateReportBuilderGuardrails(prompt);
|
|
1873
|
-
if (guardrail === null || guardrail === void 0 ? void 0 : guardrail.blocked) {
|
|
1874
|
-
return [2 /*return*/, guardrail];
|
|
1875
|
-
}
|
|
1876
|
-
}
|
|
1877
|
-
reportTypeResolution = resolveReportTypeForPrompt(input.report_type, prompt);
|
|
1878
|
-
reportType = reportTypeResolution.reportType;
|
|
1879
|
-
collectionRoot = normalizeOptionalString(input.collection_root);
|
|
1880
|
-
collectionJoins = Array.isArray(input.collection_joins) ? input.collection_joins : [];
|
|
1881
|
-
idDateField = normalizeOptionalString(input.id_date_field);
|
|
1882
|
-
dateInterval = normalizeDateInterval(input.date_interval) || reportTypeResolution.inferredDateInterval;
|
|
1883
|
-
collections = sanitizeCollections(input.available_collections || []);
|
|
1884
|
-
fieldLimit = normalizeFieldLimit(input.field_limit);
|
|
1885
|
-
resolvedFields = sanitizeFields(input.available_fields || []);
|
|
1886
|
-
usedFallbackFields = false;
|
|
1887
|
-
if (!resolvedFields.length && collections.length) {
|
|
1888
|
-
derivedFields = deriveFieldsFromCollections(collections);
|
|
1889
|
-
resolvedFields = sanitizeFields(derivedFields);
|
|
1890
|
-
usedFallbackFields = resolvedFields.length > 0;
|
|
1891
|
-
}
|
|
1892
|
-
trimmedFields = trimFieldsForPrompt(resolvedFields, fieldLimit, usedFallbackFields);
|
|
1893
|
-
arraySummary = buildArrayFieldSummary(trimmedFields.fields);
|
|
1894
|
-
systemPrompt = buildReportBuilderSystemPrompt(reportType);
|
|
1895
|
-
userPrompt = buildReportBuilderUserPrompt({
|
|
1896
|
-
prompt: prompt,
|
|
1897
|
-
reportType: reportType,
|
|
1898
|
-
reportName: normalizeOptionalString(input.report_name),
|
|
1899
|
-
collectionRoot: collectionRoot,
|
|
1900
|
-
collectionJoins: collectionJoins,
|
|
1901
|
-
idDateField: idDateField,
|
|
1902
|
-
dateInterval: dateInterval,
|
|
1903
|
-
collections: collections,
|
|
1904
|
-
fields: trimmedFields.fields,
|
|
1905
|
-
fieldMeta: {
|
|
1906
|
-
truncated: trimmedFields.truncated,
|
|
1907
|
-
total: trimmedFields.total,
|
|
1908
|
-
used: trimmedFields.fields.length
|
|
1909
|
-
},
|
|
1910
|
-
arraySummary: arraySummary
|
|
1911
|
-
});
|
|
1912
|
-
codexModel = resolveReportBuilderCodexModel(input.config);
|
|
1913
|
-
codexClient = getReportBuilderCodexClient();
|
|
1914
|
-
runOptions = {
|
|
1915
|
-
timeoutMs: resolveReportBuilderCodexTimeoutMs(input.config),
|
|
1916
|
-
threadOptions: resolveReportBuilderCodexThreadOptions(input.config, codexModel)
|
|
1917
|
-
};
|
|
1918
|
-
return [4 /*yield*/, codexClient.run(buildReportBuilderCodexPrompt(systemPrompt, userPrompt), runOptions)];
|
|
1919
|
-
case 2:
|
|
1920
|
-
responseText = _a.sent();
|
|
1921
|
-
usage = estimateUsage([
|
|
1922
|
-
{ role: 'system', content: systemPrompt },
|
|
1923
|
-
{ role: 'user', content: userPrompt }
|
|
1924
|
-
], responseText, codexModel);
|
|
1925
|
-
parsed = safeJsonParse(responseText);
|
|
1926
|
-
allowMongoRead = input.allow_mongo_read === true;
|
|
1927
|
-
if (!(allowMongoRead && parsed && typeof parsed === 'object' && parsed.mongo_read)) return [3 /*break*/, 8];
|
|
1928
|
-
mongoPayload = resolveMongoReadPayload(parsed.mongo_read, input, collections);
|
|
1929
|
-
if (!mongoPayload) return [3 /*break*/, 8];
|
|
1930
|
-
mongoReadResult = null;
|
|
1931
|
-
_a.label = 3;
|
|
1932
|
-
case 3:
|
|
1933
|
-
_a.trys.push([3, 5, , 6]);
|
|
1934
|
-
return [4 /*yield*/, (0, ai_terminal_1.executeAiAssistantMongoRead)(mongoPayload, context)];
|
|
1935
|
-
case 4:
|
|
1936
|
-
mongoReadResult = _a.sent();
|
|
1937
|
-
return [3 /*break*/, 6];
|
|
1938
|
-
case 5:
|
|
1939
|
-
error_1 = _a.sent();
|
|
1940
|
-
message = error_1 instanceof Error ? error_1.message : String(error_1 || 'Mongo read failed.');
|
|
1941
|
-
mongoReadResult = { error: message };
|
|
1942
|
-
return [3 /*break*/, 6];
|
|
1943
|
-
case 6:
|
|
1944
|
-
mongoContext = buildMongoReadContext(mongoPayload, mongoReadResult);
|
|
1945
|
-
userPrompt = buildReportBuilderUserPrompt({
|
|
1946
|
-
prompt: prompt,
|
|
1947
|
-
reportType: reportType,
|
|
1948
|
-
reportName: normalizeOptionalString(input.report_name),
|
|
1949
|
-
collectionRoot: collectionRoot,
|
|
1950
|
-
collectionJoins: collectionJoins,
|
|
1951
|
-
idDateField: idDateField,
|
|
1952
|
-
dateInterval: dateInterval,
|
|
1953
|
-
collections: collections,
|
|
1954
|
-
fields: trimmedFields.fields,
|
|
1955
|
-
fieldMeta: {
|
|
1956
|
-
truncated: trimmedFields.truncated,
|
|
1957
|
-
total: trimmedFields.total,
|
|
1958
|
-
used: trimmedFields.fields.length
|
|
1959
|
-
},
|
|
1960
|
-
arraySummary: arraySummary,
|
|
1961
|
-
mongoReadResult: mongoContext
|
|
1962
|
-
});
|
|
1963
|
-
return [4 /*yield*/, codexClient.run(buildReportBuilderCodexPrompt(systemPrompt, userPrompt), runOptions)];
|
|
1964
|
-
case 7:
|
|
1965
|
-
responseText = _a.sent();
|
|
1966
|
-
usage2 = estimateUsage([
|
|
1967
|
-
{ role: 'system', content: systemPrompt },
|
|
1968
|
-
{ role: 'user', content: userPrompt }
|
|
1969
|
-
], responseText, codexModel);
|
|
1970
|
-
usage = {
|
|
1971
|
-
inputTokens: usage.inputTokens + usage2.inputTokens,
|
|
1972
|
-
outputTokens: usage.outputTokens + usage2.outputTokens,
|
|
1973
|
-
totalTokens: usage.totalTokens + usage2.totalTokens
|
|
1974
|
-
};
|
|
1975
|
-
parsed = safeJsonParse(responseText);
|
|
1976
|
-
_a.label = 8;
|
|
1977
|
-
case 8:
|
|
1978
|
-
if (!parsed || typeof parsed !== 'object') {
|
|
1979
|
-
throw new Error('AI response was not valid JSON.');
|
|
1980
|
-
}
|
|
1981
|
-
sanitizeContext = buildSanitizerContext(collections, resolvedFields);
|
|
1982
|
-
patch = sanitizeReportBuilderPatch(parsed, sanitizeContext);
|
|
1983
|
-
patch.report_type = reportType;
|
|
1984
|
-
if (reportType === 'Dated' && !patch.date_interval && dateInterval) {
|
|
1985
|
-
patch.date_interval = dateInterval;
|
|
1986
|
-
}
|
|
1987
|
-
summaryNotes = buildPatchNotes(patch, {
|
|
1988
|
-
reportType: reportType,
|
|
1989
|
-
truncated: trimmedFields.truncated,
|
|
1990
|
-
totalFields: trimmedFields.total,
|
|
1991
|
-
usedFields: trimmedFields.fields.length,
|
|
1992
|
-
inferenceReason: reportTypeResolution.inferenceReason
|
|
1993
|
-
});
|
|
1994
|
-
return [4 /*yield*/, resolveClientId(input.id_client, context === null || context === void 0 ? void 0 : context.id_user)];
|
|
1995
|
-
case 9:
|
|
1996
|
-
idClient = _a.sent();
|
|
1997
|
-
return [4 /*yield*/, (0, openai_usage_ledger_manager_1.recordOpenAIUsage)({
|
|
1998
|
-
id_client: idClient || '',
|
|
1999
|
-
model: codexModel || 'unknown',
|
|
2000
|
-
input_tokens: usage.inputTokens,
|
|
2001
|
-
output_tokens: usage.outputTokens,
|
|
2002
|
-
total_tokens: usage.totalTokens,
|
|
2003
|
-
category: 'report-builder-ai',
|
|
2004
|
-
id_request: ''
|
|
2005
|
-
})];
|
|
2006
|
-
case 10:
|
|
2007
|
-
_a.sent();
|
|
2008
|
-
return [2 /*return*/, {
|
|
2009
|
-
patch: patch,
|
|
2010
|
-
notes: summaryNotes,
|
|
2011
|
-
usage: {
|
|
2012
|
-
input_tokens: usage.inputTokens,
|
|
2013
|
-
output_tokens: usage.outputTokens,
|
|
2014
|
-
total_tokens: usage.totalTokens
|
|
2015
|
-
},
|
|
2016
|
-
model: codexModel
|
|
2017
|
-
}];
|
|
2018
|
-
}
|
|
2019
|
-
});
|
|
2020
|
-
});
|
|
2021
|
-
}
|
|
2022
|
-
function buildReportBuilderSystemPrompt(reportType) {
|
|
2023
|
-
return [
|
|
2024
|
-
'You are a report builder configuration assistant.',
|
|
2025
|
-
'Return ONLY a JSON object (no markdown).',
|
|
2026
|
-
'Schema keys:',
|
|
2027
|
-
'- report_name (string)',
|
|
2028
|
-
'- collection_root (string)',
|
|
2029
|
-
'- collection_joins (array of { collection, alias })',
|
|
2030
|
-
'- layout_columns (array of { header, field_path, collection, mode, text, leaf_value_type, leaf_format_type, show })',
|
|
2031
|
-
'- groups_row (array of field_path strings)',
|
|
2032
|
-
'- filters (array of { field_path, condition, value, high_value, boolean_value, is_rolling, rolling_interval })',
|
|
2033
|
-
'- sort (array of { field_path, order })',
|
|
2034
|
-
'- totals (array of { type, fields })',
|
|
2035
|
-
'- links (array of { field_first, field_second })',
|
|
2036
|
-
'- id_date_field (string)',
|
|
2037
|
-
'- date_interval (Seconds|Minutes|Hours|Daily|Weekly|Monthly|Quarterly|Yearly)',
|
|
2038
|
-
'- notes (string)',
|
|
2039
|
-
'Use only provided collections and field_path values (they reflect the current models/collections).',
|
|
2040
|
-
'Always set collection_root to the best matching collection from available_collections.',
|
|
2041
|
-
'When available_fields spans multiple collections, choose collection_root first and then select fields whose collection_name matches collection_root or a join alias.',
|
|
2042
|
-
'Prefer exact field_path values from available_fields; never invent field paths.',
|
|
2043
|
-
'Translate the request into concrete layout_columns, groups_row, sort, totals, filters, and links whenever possible.',
|
|
2044
|
-
'Every layout column must be complete: include a header plus at least one mapping with a valid field_path (or text mode with non-empty text). Do not return columns without mapped fields.',
|
|
2045
|
-
'Unless the user explicitly asks for a different order, add sort entries for the primary grouping/identifier fields (groups_row or the first key layout_columns) using ascending order so results are alphabetical.',
|
|
2046
|
-
'Always prioritize sort on popular business keys when available: name, company, item (fallback: title, label, customer). Keep ascending unless user asks otherwise.',
|
|
2047
|
-
'If no popular key exists, add stable fallback sort using createdAt/date_created then _id.',
|
|
2048
|
-
'Use filters with explicit boolean logic: $and for required constraints and $or for alternate matches.',
|
|
2049
|
-
'Use custom fields when the request asks for derived metrics (ratios, percentages, margins, computed totals).',
|
|
2050
|
-
'If the request specifies a time grain (daily/weekly/monthly/etc), set date_interval and id_date_field to the best matching date field.',
|
|
2051
|
-
'Treat requests like "over the last X", "by month", "by quarter", and "by <time period>" as Dated report intent.',
|
|
2052
|
-
'If you need sample records to confirm field choices, you may return JSON with {"mongo_read": { "collection": "<collection>", "query": {}, "options": {"limit": 5} }, "notes": "why you need data"} .',
|
|
2053
|
-
'Only request mongo_read when necessary and only use collections from available_collections.',
|
|
2054
|
-
'When mongo_read_result is present in the user context, use it to finalize the patch and do not request another read.',
|
|
2055
|
-
'Use field_type to guide filters/totals (numeric fields for totals, date fields for date_interval, boolean fields for boolean_value).',
|
|
2056
|
-
'If field_summary.truncated is true, only use provided fields and note missing needs in notes.',
|
|
2057
|
-
'If you need joined data, add collection_joins with an alias and use the alias in field_path.',
|
|
2058
|
-
'When fields require related records, use lookup paths and joins rather than guessing flat field names.',
|
|
2059
|
-
'array_summary lists array roots and candidate key_fields for linking arrays.',
|
|
2060
|
-
'If you select fields from multiple array roots, add links that align arrays using shared identifiers (_id or id_<x> style keys).',
|
|
2061
|
-
'Avoid mixing unrelated array roots without links; prefer a single array root or non-array fields to prevent duplicate rows.',
|
|
2062
|
-
'Return a single valid JSON object with double quotes and no trailing commas.',
|
|
2063
|
-
'Omit keys you cannot confidently fill.',
|
|
2064
|
-
'Conditions allowed: eq, ne, lt, lte, gt, gte, bw, nnull, null, regex.',
|
|
2065
|
-
"Report type: ".concat(reportType || 'List', ". Ensure groups_row is set for Group/Dated reports."),
|
|
2066
|
-
'If unsure, leave a section empty instead of guessing.'
|
|
2067
|
-
].join('\n');
|
|
2068
|
-
}
|
|
2069
|
-
function buildReportBuilderUserPrompt(input) {
|
|
2070
|
-
var context = {
|
|
2071
|
-
report_type: input.reportType || 'List',
|
|
2072
|
-
current: {
|
|
2073
|
-
report_name: input.reportName || '',
|
|
2074
|
-
collection_root: input.collectionRoot || '',
|
|
2075
|
-
collection_joins: input.collectionJoins || [],
|
|
2076
|
-
id_date_field: input.idDateField || '',
|
|
2077
|
-
date_interval: input.dateInterval || ''
|
|
2078
|
-
},
|
|
2079
|
-
available_collections: input.collections || [],
|
|
2080
|
-
available_fields: input.fields || [],
|
|
2081
|
-
field_summary: input.fieldMeta || undefined,
|
|
2082
|
-
array_summary: input.arraySummary || [],
|
|
2083
|
-
mongo_read_result: input.mongoReadResult || undefined,
|
|
2084
|
-
request: input.prompt
|
|
2085
|
-
};
|
|
2086
|
-
return JSON.stringify(context);
|
|
2087
|
-
}
|
|
2088
|
-
function resolveReportBuilderCodexTimeoutMs(config) {
|
|
2089
|
-
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2090
|
-
var raw = normalizeOptionalNumber((config === null || config === void 0 ? void 0 : config.timeout_ms)
|
|
2091
|
-
|| serverConfig['REPORT_BUILDER_CODEX_TIMEOUT_MS']
|
|
2092
|
-
|| process.env.REPORT_BUILDER_CODEX_TIMEOUT_MS);
|
|
2093
|
-
if (raw && raw > 0) {
|
|
2094
|
-
return (0, common_1.round)(raw);
|
|
2095
|
-
}
|
|
2096
|
-
return DEFAULT_REPORT_BUILDER_CODEX_TIMEOUT_MS;
|
|
2097
|
-
}
|
|
2098
|
-
function resolveReportBuilderCodexModel(config) {
|
|
2099
|
-
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2100
|
-
var overrideModel = normalizeOptionalString(config === null || config === void 0 ? void 0 : config.model);
|
|
2101
|
-
var raw = overrideModel
|
|
2102
|
-
|| normalizeOptionalString(serverConfig['REPORT_BUILDER_CODEX_MODEL'] || process.env.REPORT_BUILDER_CODEX_MODEL)
|
|
2103
|
-
|| normalizeOptionalString(serverConfig['AI_DASHBOARD_CODEX_MODEL'] || process.env.AI_DASHBOARD_CODEX_MODEL)
|
|
2104
|
-
|| normalizeOptionalString(serverConfig['AI_TERMINAL_CODEX_MODEL'] || process.env.AI_TERMINAL_CODEX_MODEL)
|
|
2105
|
-
|| normalizeOptionalString(serverConfig['AI_ASSISTANT_CODEX_MODEL'] || process.env.AI_ASSISTANT_CODEX_MODEL);
|
|
2106
|
-
return raw;
|
|
2107
|
-
}
|
|
2108
|
-
function resolveReportBuilderCodexFallbackModels(model) {
|
|
2109
|
-
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2110
|
-
var primary = normalizeOptionalString(model || resolveReportBuilderCodexModel());
|
|
2111
|
-
var models = [];
|
|
2112
|
-
var push = function (value) {
|
|
2113
|
-
var normalized = normalizeOptionalString(value);
|
|
2114
|
-
if (!normalized || normalized === primary || models.includes(normalized)) {
|
|
2115
|
-
return;
|
|
2116
|
-
}
|
|
2117
|
-
models.push(normalized);
|
|
2118
|
-
};
|
|
2119
|
-
var parseList = function (value) { return normalizeOptionalString(value)
|
|
2120
|
-
.split(',')
|
|
2121
|
-
.map(function (entry) { return normalizeOptionalString(entry); })
|
|
2122
|
-
.filter(Boolean)
|
|
2123
|
-
.forEach(push); };
|
|
2124
|
-
parseList(serverConfig['REPORT_BUILDER_CODEX_FALLBACK_MODELS'] || process.env.REPORT_BUILDER_CODEX_FALLBACK_MODELS);
|
|
2125
|
-
push(serverConfig['REPORT_BUILDER_CODEX_FALLBACK_MODEL'] || process.env.REPORT_BUILDER_CODEX_FALLBACK_MODEL);
|
|
2126
|
-
parseList(serverConfig['AI_DASHBOARD_CODEX_FALLBACK_MODELS'] || process.env.AI_DASHBOARD_CODEX_FALLBACK_MODELS);
|
|
2127
|
-
push(serverConfig['AI_DASHBOARD_CODEX_FALLBACK_MODEL'] || process.env.AI_DASHBOARD_CODEX_FALLBACK_MODEL);
|
|
2128
|
-
parseList(serverConfig['AI_TERMINAL_CODEX_FALLBACK_MODELS'] || process.env.AI_TERMINAL_CODEX_FALLBACK_MODELS);
|
|
2129
|
-
push(serverConfig['AI_TERMINAL_CODEX_FALLBACK_MODEL'] || process.env.AI_TERMINAL_CODEX_FALLBACK_MODEL);
|
|
2130
|
-
parseList(serverConfig['AI_ASSISTANT_CODEX_FALLBACK_MODELS'] || process.env.AI_ASSISTANT_CODEX_FALLBACK_MODELS);
|
|
2131
|
-
push(serverConfig['AI_ASSISTANT_CODEX_FALLBACK_MODEL'] || process.env.AI_ASSISTANT_CODEX_FALLBACK_MODEL);
|
|
2132
|
-
return models;
|
|
2133
|
-
}
|
|
2134
|
-
function resolveReportBuilderCodexSettings() {
|
|
2135
|
-
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2136
|
-
var apiKey = (serverConfig['OPENAI_API_KEY'] || process.env.OPENAI_API_KEY || '').trim();
|
|
2137
|
-
if (!apiKey) {
|
|
2138
|
-
throw new Error('AI API key missing. Add an AI API key to server config.');
|
|
2139
|
-
}
|
|
2140
|
-
var model = resolveReportBuilderCodexModel();
|
|
2141
|
-
var fallbackModels = resolveReportBuilderCodexFallbackModels(model);
|
|
2142
|
-
return __assign(__assign(__assign({ apiKey: apiKey, baseUrl: (serverConfig['OPENAI_BASE_URL'] || process.env.OPENAI_BASE_URL || '').trim() || undefined }, (model ? { model: model } : {})), (fallbackModels.length ? { fallbackModel: fallbackModels[0], fallbackModels: fallbackModels } : {})), { maxRetries: normalizeOptionalNumber(serverConfig['OPENAI_MAX_RETRIES'] || process.env.OPENAI_MAX_RETRIES), retryDelayMs: normalizeOptionalNumber(serverConfig['OPENAI_RETRY_DELAY_MS'] || process.env.OPENAI_RETRY_DELAY_MS) });
|
|
2143
|
-
}
|
|
2144
|
-
function resolveReportBuilderCodexThreadOptions(config, model) {
|
|
2145
|
-
var serverConfig = resolveio_server_app_1.ResolveIOServer.getServerConfig() || {};
|
|
2146
|
-
var effort = normalizeReasoningEffort((config === null || config === void 0 ? void 0 : config.reasoning_effort)
|
|
2147
|
-
|| serverConfig['REPORT_BUILDER_CODEX_REASONING_EFFORT']
|
|
2148
|
-
|| process.env.REPORT_BUILDER_CODEX_REASONING_EFFORT) || 'low';
|
|
2149
|
-
return __assign(__assign({}, (model ? { model: model } : {})), { sandboxMode: 'read-only', skipGitRepoCheck: true, modelReasoningEffort: effort, networkAccessEnabled: false, webSearchMode: 'disabled', webSearchEnabled: false, approvalPolicy: 'never' });
|
|
2150
|
-
}
|
|
2151
|
-
function getReportBuilderCodexClient() {
|
|
2152
|
-
if (!reportBuilderCodexClient) {
|
|
2153
|
-
reportBuilderCodexClient = new codex_client_1.CodexClient(resolveReportBuilderCodexSettings());
|
|
2154
|
-
}
|
|
2155
|
-
return reportBuilderCodexClient;
|
|
2156
|
-
}
|
|
2157
|
-
function buildReportBuilderCodexPrompt(systemPrompt, userPrompt) {
|
|
2158
|
-
return "System:\n".concat(systemPrompt, "\n\nUser:\n").concat(userPrompt).trim();
|
|
2159
|
-
}
|
|
2160
|
-
function resolveReportTypeForPrompt(inputType, prompt) {
|
|
2161
|
-
var requestedType = normalizeReportType(inputType);
|
|
2162
|
-
var inferredInterval = inferDateIntervalFromPrompt(prompt);
|
|
2163
|
-
if (!isDatedPrompt(prompt)) {
|
|
2164
|
-
return {
|
|
2165
|
-
reportType: requestedType,
|
|
2166
|
-
inferenceReason: '',
|
|
2167
|
-
inferredDateInterval: inferredInterval
|
|
2168
|
-
};
|
|
2169
|
-
}
|
|
2170
|
-
var reason = requestedType !== 'Dated'
|
|
2171
|
-
? 'Auto-inferred Dated report from time-period language in the request.'
|
|
2172
|
-
: '';
|
|
2173
|
-
return {
|
|
2174
|
-
reportType: 'Dated',
|
|
2175
|
-
inferenceReason: reason,
|
|
2176
|
-
inferredDateInterval: inferredInterval
|
|
2177
|
-
};
|
|
2178
|
-
}
|
|
2179
|
-
function isDatedPrompt(prompt) {
|
|
2180
|
-
var text = normalizeOptionalString(prompt).toLowerCase();
|
|
2181
|
-
if (!text) {
|
|
2182
|
-
return false;
|
|
2183
|
-
}
|
|
2184
|
-
var patterns = [
|
|
2185
|
-
/\b(by|per)\s+(day|week|month|quarter|year|hour|minute|second)s?\b/i,
|
|
2186
|
-
/\b(daily|weekly|monthly|quarterly|yearly)\b/i,
|
|
2187
|
-
/\b(last|past|previous|recent)\s+(?:\d+|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)\s+(day|week|month|quarter|year|hour|minute|second)s?\b/i,
|
|
2188
|
-
/\bover\s+the\s+last\s+(?:\d+|one|two|three|four|five|six|seven|eight|nine|ten|eleven|twelve)\s+(day|week|month|quarter|year|hour|minute|second)s?\b/i,
|
|
2189
|
-
/\b(month|quarter|year)\s+over\s+(month|quarter|year)\b/i,
|
|
2190
|
-
/\b(over\s+time|time\s*series|trend(?:ing|s)?)\b/i,
|
|
2191
|
-
/\bby\s+(?:a\s+)?(?:time|date)\s+period\b/i,
|
|
2192
|
-
/\bby\s+period\b/i
|
|
2193
|
-
];
|
|
2194
|
-
return patterns.some(function (pattern) { return pattern.test(text); });
|
|
2195
|
-
}
|
|
2196
|
-
function inferDateIntervalFromPrompt(prompt) {
|
|
2197
|
-
var text = normalizeOptionalString(prompt).toLowerCase();
|
|
2198
|
-
if (!text) {
|
|
2199
|
-
return '';
|
|
2200
|
-
}
|
|
2201
|
-
var mapping = [
|
|
2202
|
-
{ interval: 'Quarterly', pattern: /\b(quarter|quarters|quarterly|qoq)\b/i },
|
|
2203
|
-
{ interval: 'Monthly', pattern: /\b(month|months|monthly|mom)\b/i },
|
|
2204
|
-
{ interval: 'Weekly', pattern: /\b(week|weeks|weekly|wow)\b/i },
|
|
2205
|
-
{ interval: 'Daily', pattern: /\b(day|days|daily)\b/i },
|
|
2206
|
-
{ interval: 'Yearly', pattern: /\b(year|years|yearly|yoy)\b/i },
|
|
2207
|
-
{ interval: 'Hours', pattern: /\b(hour|hours|hourly)\b/i },
|
|
2208
|
-
{ interval: 'Minutes', pattern: /\b(minute|minutes)\b/i },
|
|
2209
|
-
{ interval: 'Seconds', pattern: /\b(second|seconds)\b/i }
|
|
2210
|
-
];
|
|
2211
|
-
var matched = mapping.find(function (entry) { return entry.pattern.test(text); });
|
|
2212
|
-
return (matched === null || matched === void 0 ? void 0 : matched.interval) || '';
|
|
2213
|
-
}
|
|
2214
|
-
function normalizeReportType(value) {
|
|
2215
|
-
var normalized = normalizeOptionalString(value);
|
|
2216
|
-
if (normalized.toLowerCase() === 'group') {
|
|
2217
|
-
return 'Group';
|
|
2218
|
-
}
|
|
2219
|
-
if (normalized.toLowerCase() === 'dated') {
|
|
2220
|
-
return 'Dated';
|
|
2221
|
-
}
|
|
2222
|
-
return normalized ? (0, common_1.toTitleCase)(normalized) : 'List';
|
|
2223
|
-
}
|
|
2224
|
-
function normalizeOptionalString(value) {
|
|
2225
|
-
var raw = typeof value === 'string' ? value.trim() : '';
|
|
2226
|
-
return raw || '';
|
|
2227
|
-
}
|
|
2228
|
-
function normalizeOptionalNumber(value) {
|
|
2229
|
-
var parsed = Number(value);
|
|
2230
|
-
return Number.isFinite(parsed) ? parsed : undefined;
|
|
2231
|
-
}
|
|
2232
|
-
function normalizeReasoningEffort(value) {
|
|
2233
|
-
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
2234
|
-
var allowed = new Set(['minimal', 'low', 'medium', 'high', 'xhigh']);
|
|
2235
|
-
return allowed.has(normalized) ? normalized : undefined;
|
|
2236
|
-
}
|
|
2237
|
-
function normalizeFieldLimit(value) {
|
|
2238
|
-
var parsed = Number(value);
|
|
2239
|
-
if (!Number.isFinite(parsed)) {
|
|
2240
|
-
return 600;
|
|
2241
|
-
}
|
|
2242
|
-
return Math.max(50, Math.min((0, common_1.round)(parsed), 2000));
|
|
2243
|
-
}
|
|
2244
|
-
function estimateUsage(messages, responseText, model) {
|
|
2245
|
-
var inputTokens = (0, tokenizer_1.countChatTokens)(messages, model);
|
|
2246
|
-
var outputTokens = (0, tokenizer_1.countTokens)(responseText || '', model);
|
|
2247
|
-
return {
|
|
2248
|
-
inputTokens: inputTokens,
|
|
2249
|
-
outputTokens: outputTokens,
|
|
2250
|
-
totalTokens: inputTokens + outputTokens
|
|
2251
|
-
};
|
|
2252
|
-
}
|
|
2253
|
-
function sanitizeCollections(raw) {
|
|
2254
|
-
var out = [];
|
|
2255
|
-
var seen = new Set();
|
|
2256
|
-
(raw || []).forEach(function (entry) {
|
|
2257
|
-
var collection = normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.collection);
|
|
2258
|
-
if (!collection) {
|
|
2259
|
-
return;
|
|
2260
|
-
}
|
|
2261
|
-
var key = collection.toLowerCase();
|
|
2262
|
-
if (seen.has(key)) {
|
|
2263
|
-
return;
|
|
2264
|
-
}
|
|
2265
|
-
seen.add(key);
|
|
2266
|
-
out.push({
|
|
2267
|
-
collection: collection,
|
|
2268
|
-
name: normalizeOptionalString(entry === null || entry === void 0 ? void 0 : entry.name) || (0, common_1.toTitleCase)(collection.replace(/[-_]/g, ' '))
|
|
2269
|
-
});
|
|
2270
|
-
});
|
|
2271
|
-
return out;
|
|
2272
|
-
}
|
|
2273
|
-
function sanitizeFields(raw) {
|
|
2274
|
-
var out = [];
|
|
2275
|
-
var seen = new Set();
|
|
2276
|
-
(raw || []).forEach(function (entry) {
|
|
2277
|
-
var fieldPath = normalizeOptionalString((entry === null || entry === void 0 ? void 0 : entry.field_path) || (entry === null || entry === void 0 ? void 0 : entry.fieldPath));
|
|
2278
|
-
if (!fieldPath) {
|
|
2279
|
-
return;
|
|
2280
|
-
}
|
|
2281
|
-
var key = fieldPath.toLowerCase();
|
|
2282
|
-
if (seen.has(key)) {
|
|
2283
|
-
return;
|
|
2284
|
-
}
|
|
2285
|
-
seen.add(key);
|
|
2286
|
-
out.push({
|
|
2287
|
-
field_path: fieldPath,
|
|
2288
|
-
field_path_name: normalizeOptionalString((entry === null || entry === void 0 ? void 0 : entry.field_path_name) || (entry === null || entry === void 0 ? void 0 : entry.fieldPathName) || (entry === null || entry === void 0 ? void 0 : entry.field_name)) || fieldPath,
|
|
2289
|
-
field_type: normalizeOptionalString((entry === null || entry === void 0 ? void 0 : entry.field_type) || (entry === null || entry === void 0 ? void 0 : entry.fieldType) || (entry === null || entry === void 0 ? void 0 : entry.field_type_name) || (entry === null || entry === void 0 ? void 0 : entry.fieldTypeName)) || 'String',
|
|
2290
|
-
collection_name: normalizeOptionalString((entry === null || entry === void 0 ? void 0 : entry.collection_name) || (entry === null || entry === void 0 ? void 0 : entry.collectionName) || (entry === null || entry === void 0 ? void 0 : entry.collection)) || ''
|
|
2291
|
-
});
|
|
2292
|
-
});
|
|
2293
|
-
return out;
|
|
2294
|
-
}
|
|
2295
|
-
function resolveCollectionNameFromList(value, collections) {
|
|
2296
|
-
var e_1, _a;
|
|
2297
|
-
var key = normalizeKey(value);
|
|
2298
|
-
if (!key) {
|
|
2299
|
-
return '';
|
|
2300
|
-
}
|
|
2301
|
-
try {
|
|
2302
|
-
for (var _b = __values(collections || []), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
2303
|
-
var col = _c.value;
|
|
2304
|
-
if (normalizeKey(col.collection) === key || normalizeKey(col.name) === key) {
|
|
2305
|
-
return col.collection;
|
|
2306
|
-
}
|
|
2307
|
-
}
|
|
2308
|
-
}
|
|
2309
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
2310
|
-
finally {
|
|
2311
|
-
try {
|
|
2312
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
2313
|
-
}
|
|
2314
|
-
finally { if (e_1) throw e_1.error; }
|
|
2315
|
-
}
|
|
2316
|
-
return '';
|
|
2317
|
-
}
|
|
2318
|
-
function resolveMongoReadPayload(raw, input, collections) {
|
|
2319
|
-
if (!raw || typeof raw !== 'object') {
|
|
2320
|
-
return null;
|
|
2321
|
-
}
|
|
2322
|
-
var collection = resolveCollectionNameFromList(raw.collection || raw.collection_name || raw.collectionName, collections);
|
|
2323
|
-
if (!collection) {
|
|
2324
|
-
return null;
|
|
2325
|
-
}
|
|
2326
|
-
var query = raw.query && typeof raw.query === 'object' && !Array.isArray(raw.query) ? raw.query : {};
|
|
2327
|
-
var optionsRaw = raw.options && typeof raw.options === 'object' ? raw.options : {};
|
|
2328
|
-
var limitRaw = normalizeOptionalNumber(optionsRaw.limit);
|
|
2329
|
-
var skipRaw = normalizeOptionalNumber(optionsRaw.skip);
|
|
2330
|
-
var permissionView = normalizeOptionalString(input.permission_view || input.permissionView) || '/report-builder';
|
|
2331
|
-
var request = {
|
|
2332
|
-
collection: collection,
|
|
2333
|
-
database: normalizeOptionalString(raw.database) || undefined,
|
|
2334
|
-
query: query,
|
|
2335
|
-
options: {
|
|
2336
|
-
projection: optionsRaw.projection && typeof optionsRaw.projection === 'object' ? optionsRaw.projection : undefined,
|
|
2337
|
-
sort: optionsRaw.sort && typeof optionsRaw.sort === 'object' ? optionsRaw.sort : undefined,
|
|
2338
|
-
limit: limitRaw ? Math.min(Math.max((0, common_1.round)(limitRaw), 1), 10) : 5,
|
|
2339
|
-
skip: skipRaw ? Math.max((0, common_1.round)(skipRaw), 0) : undefined,
|
|
2340
|
-
includeTotal: optionsRaw.includeTotal === true
|
|
2341
|
-
},
|
|
2342
|
-
permissionView: permissionView || undefined,
|
|
2343
|
-
id_client: normalizeOptionalString(input.id_client) || undefined,
|
|
2344
|
-
mongo: input.mongo
|
|
2345
|
-
};
|
|
2346
|
-
return request;
|
|
2347
|
-
}
|
|
2348
|
-
function buildMongoReadContext(request, response) {
|
|
2349
|
-
var documents = Array.isArray(response === null || response === void 0 ? void 0 : response.documents) ? response.documents : [];
|
|
2350
|
-
var total = typeof (response === null || response === void 0 ? void 0 : response.total) === 'number' ? response.total : null;
|
|
2351
|
-
var sample = summarizeMongoDocuments(documents);
|
|
2352
|
-
return {
|
|
2353
|
-
request: {
|
|
2354
|
-
collection: request.collection,
|
|
2355
|
-
query: request.query || {},
|
|
2356
|
-
options: request.options || {}
|
|
2357
|
-
},
|
|
2358
|
-
result: {
|
|
2359
|
-
total: total,
|
|
2360
|
-
sample: sample,
|
|
2361
|
-
fields: extractMongoSampleFields(sample)
|
|
2362
|
-
}
|
|
2363
|
-
};
|
|
2364
|
-
}
|
|
2365
|
-
function summarizeMongoDocuments(documents) {
|
|
2366
|
-
var maxDocs = 5;
|
|
2367
|
-
return (documents || []).slice(0, maxDocs).map(function (doc) { return pruneMongoValue(doc, 0); });
|
|
2368
|
-
}
|
|
2369
|
-
function pruneMongoValue(value, depth) {
|
|
2370
|
-
var maxDepth = 3;
|
|
2371
|
-
var maxKeys = 30;
|
|
2372
|
-
var maxArray = 8;
|
|
2373
|
-
var maxString = 200;
|
|
2374
|
-
if (depth >= maxDepth) {
|
|
2375
|
-
return '[Truncated]';
|
|
2376
|
-
}
|
|
2377
|
-
if (Array.isArray(value)) {
|
|
2378
|
-
return value.slice(0, maxArray).map(function (item) { return pruneMongoValue(item, depth + 1); });
|
|
2379
|
-
}
|
|
2380
|
-
if (value && typeof value === 'object') {
|
|
2381
|
-
var keys = Object.keys(value);
|
|
2382
|
-
var trimmedKeys = keys.slice(0, maxKeys);
|
|
2383
|
-
var result_1 = {};
|
|
2384
|
-
trimmedKeys.forEach(function (key) {
|
|
2385
|
-
result_1[key] = pruneMongoValue(value[key], depth + 1);
|
|
2386
|
-
});
|
|
2387
|
-
if (keys.length > trimmedKeys.length) {
|
|
2388
|
-
result_1.__truncated__ = true;
|
|
2389
|
-
}
|
|
2390
|
-
return result_1;
|
|
2391
|
-
}
|
|
2392
|
-
if (typeof value === 'string' && value.length > maxString) {
|
|
2393
|
-
return value.slice(0, maxString) + '...';
|
|
2394
|
-
}
|
|
2395
|
-
return value;
|
|
2396
|
-
}
|
|
2397
|
-
function extractMongoSampleFields(samples) {
|
|
2398
|
-
var fields = new Set();
|
|
2399
|
-
(samples || []).forEach(function (sample) {
|
|
2400
|
-
if (!sample || typeof sample !== 'object') {
|
|
2401
|
-
return;
|
|
2402
|
-
}
|
|
2403
|
-
Object.keys(sample).forEach(function (key) { return fields.add(key); });
|
|
2404
|
-
});
|
|
2405
|
-
return Array.from(fields);
|
|
2406
|
-
}
|
|
2407
|
-
function collectTreeLeaves(items, res) {
|
|
2408
|
-
(items || []).forEach(function (item) {
|
|
2409
|
-
var _a;
|
|
2410
|
-
if (item === null || item === void 0 ? void 0 : item.isLeaf) {
|
|
2411
|
-
res.push(item);
|
|
2412
|
-
return;
|
|
2413
|
-
}
|
|
2414
|
-
if ((_a = item === null || item === void 0 ? void 0 : item.children) === null || _a === void 0 ? void 0 : _a.length) {
|
|
2415
|
-
collectTreeLeaves(item.children, res);
|
|
2416
|
-
}
|
|
2417
|
-
});
|
|
2418
|
-
}
|
|
2419
|
-
function deriveFieldsFromCollections(collections) {
|
|
2420
|
-
var fields = [];
|
|
2421
|
-
var seen = new Set();
|
|
2422
|
-
(collections || []).forEach(function (col) {
|
|
2423
|
-
var collectionName = normalizeOptionalString(col === null || col === void 0 ? void 0 : col.collection);
|
|
2424
|
-
if (!collectionName) {
|
|
2425
|
-
return;
|
|
2426
|
-
}
|
|
2427
|
-
var tree;
|
|
2428
|
-
try {
|
|
2429
|
-
tree = buildCollectionTree(collectionName);
|
|
2430
|
-
}
|
|
2431
|
-
catch (error) {
|
|
2432
|
-
var message = error instanceof Error ? error.message : String(error || 'Unknown error');
|
|
2433
|
-
console.warn('RB AI field derivation failed', { collection: collectionName, error: message });
|
|
2434
|
-
return;
|
|
2435
|
-
}
|
|
2436
|
-
var leaves = [];
|
|
2437
|
-
collectTreeLeaves((tree === null || tree === void 0 ? void 0 : tree.children) || [], leaves);
|
|
2438
|
-
leaves.forEach(function (leaf) {
|
|
2439
|
-
var fieldPath = normalizeOptionalString(leaf === null || leaf === void 0 ? void 0 : leaf.fieldPath);
|
|
2440
|
-
if (!fieldPath) {
|
|
2441
|
-
return;
|
|
2442
|
-
}
|
|
2443
|
-
var key = fieldPath.toLowerCase();
|
|
2444
|
-
if (seen.has(key)) {
|
|
2445
|
-
return;
|
|
2446
|
-
}
|
|
2447
|
-
seen.add(key);
|
|
2448
|
-
fields.push({
|
|
2449
|
-
field_path: fieldPath,
|
|
2450
|
-
field_path_name: normalizeOptionalString(leaf === null || leaf === void 0 ? void 0 : leaf.fieldPathName) || fieldPath,
|
|
2451
|
-
field_type: normalizeOptionalString(leaf === null || leaf === void 0 ? void 0 : leaf.fieldType) || 'String',
|
|
2452
|
-
collection_name: normalizeOptionalString((leaf === null || leaf === void 0 ? void 0 : leaf.collection_name) || (leaf === null || leaf === void 0 ? void 0 : leaf.collection)) || collectionName
|
|
2453
|
-
});
|
|
2454
|
-
});
|
|
2455
|
-
});
|
|
2456
|
-
return fields;
|
|
2457
|
-
}
|
|
2458
|
-
function trimFieldsForPrompt(fields, limit, balanceByCollection) {
|
|
2459
|
-
var e_2, _a;
|
|
2460
|
-
if (balanceByCollection === void 0) { balanceByCollection = false; }
|
|
2461
|
-
if (!fields || !fields.length) {
|
|
2462
|
-
return { fields: [], truncated: false, total: 0 };
|
|
2463
|
-
}
|
|
2464
|
-
if (fields.length <= limit) {
|
|
2465
|
-
return { fields: fields, truncated: false, total: fields.length };
|
|
2466
|
-
}
|
|
2467
|
-
if (balanceByCollection) {
|
|
2468
|
-
var buckets_1 = new Map();
|
|
2469
|
-
var order_1 = [];
|
|
2470
|
-
fields.forEach(function (field) {
|
|
2471
|
-
var _a;
|
|
2472
|
-
var key = normalizeOptionalString(field === null || field === void 0 ? void 0 : field.collection_name) || 'unknown';
|
|
2473
|
-
if (!buckets_1.has(key)) {
|
|
2474
|
-
buckets_1.set(key, []);
|
|
2475
|
-
order_1.push(key);
|
|
2476
|
-
}
|
|
2477
|
-
(_a = buckets_1.get(key)) === null || _a === void 0 ? void 0 : _a.push(field);
|
|
2478
|
-
});
|
|
2479
|
-
if (buckets_1.size > 1) {
|
|
2480
|
-
var trackers = order_1.map(function (key) { return ({
|
|
2481
|
-
key: key,
|
|
2482
|
-
list: buckets_1.get(key) || [],
|
|
2483
|
-
index: 0
|
|
2484
|
-
}); });
|
|
2485
|
-
var trimmed_1 = [];
|
|
2486
|
-
var added = true;
|
|
2487
|
-
while (trimmed_1.length < limit && added) {
|
|
2488
|
-
added = false;
|
|
2489
|
-
try {
|
|
2490
|
-
for (var trackers_1 = (e_2 = void 0, __values(trackers)), trackers_1_1 = trackers_1.next(); !trackers_1_1.done; trackers_1_1 = trackers_1.next()) {
|
|
2491
|
-
var tracker = trackers_1_1.value;
|
|
2492
|
-
if (trimmed_1.length >= limit) {
|
|
2493
|
-
break;
|
|
2494
|
-
}
|
|
2495
|
-
if (tracker.index < tracker.list.length) {
|
|
2496
|
-
trimmed_1.push(tracker.list[tracker.index]);
|
|
2497
|
-
tracker.index += 1;
|
|
2498
|
-
added = true;
|
|
2499
|
-
}
|
|
2500
|
-
}
|
|
2501
|
-
}
|
|
2502
|
-
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
2503
|
-
finally {
|
|
2504
|
-
try {
|
|
2505
|
-
if (trackers_1_1 && !trackers_1_1.done && (_a = trackers_1.return)) _a.call(trackers_1);
|
|
2506
|
-
}
|
|
2507
|
-
finally { if (e_2) throw e_2.error; }
|
|
2508
|
-
}
|
|
2509
|
-
}
|
|
2510
|
-
return { fields: trimmed_1, truncated: true, total: fields.length };
|
|
2511
|
-
}
|
|
2512
|
-
}
|
|
2513
|
-
var trimmed = fields.slice(0, limit);
|
|
2514
|
-
return { fields: trimmed, truncated: true, total: fields.length };
|
|
2515
|
-
}
|
|
2516
|
-
function buildArrayFieldSummary(fields) {
|
|
2517
|
-
var roots = new Map();
|
|
2518
|
-
(fields || []).forEach(function (field) {
|
|
2519
|
-
var fieldPath = normalizeOptionalString(field === null || field === void 0 ? void 0 : field.field_path);
|
|
2520
|
-
if (!fieldPath || !fieldPath.includes('.$')) {
|
|
2521
|
-
return;
|
|
2522
|
-
}
|
|
2523
|
-
var root = resolveArrayRoot(fieldPath);
|
|
2524
|
-
if (!root) {
|
|
2525
|
-
return;
|
|
2526
|
-
}
|
|
2527
|
-
var entry = roots.get(root);
|
|
2528
|
-
if (!entry) {
|
|
2529
|
-
entry = { root_path: root, key_fields: [], sample_fields: [] };
|
|
2530
|
-
roots.set(root, entry);
|
|
2531
|
-
}
|
|
2532
|
-
if (!entry.sample_fields.includes(fieldPath) && entry.sample_fields.length < 8) {
|
|
2533
|
-
entry.sample_fields.push(fieldPath);
|
|
2534
|
-
}
|
|
2535
|
-
if (isLinkCandidateFieldPath(fieldPath) && !entry.key_fields.includes(fieldPath) && entry.key_fields.length < 8) {
|
|
2536
|
-
entry.key_fields.push(fieldPath);
|
|
2537
|
-
}
|
|
2538
|
-
});
|
|
2539
|
-
return Array.from(roots.values());
|
|
2540
|
-
}
|
|
2541
|
-
function buildSanitizerContext(collections, fields) {
|
|
2542
|
-
var collectionIndex = new Map();
|
|
2543
|
-
var fieldIndex = new Map();
|
|
2544
|
-
var fieldNameIndex = new Map();
|
|
2545
|
-
collections.forEach(function (col) {
|
|
2546
|
-
var key = normalizeKey(col.collection);
|
|
2547
|
-
if (key) {
|
|
2548
|
-
collectionIndex.set(key, col);
|
|
2549
|
-
}
|
|
2550
|
-
var nameKey = normalizeKey(col.name);
|
|
2551
|
-
if (nameKey) {
|
|
2552
|
-
collectionIndex.set(nameKey, col);
|
|
2553
|
-
}
|
|
2554
|
-
});
|
|
2555
|
-
fields.forEach(function (field) {
|
|
2556
|
-
var pathKey = normalizePathKey(field.field_path);
|
|
2557
|
-
if (pathKey) {
|
|
2558
|
-
fieldIndex.set(pathKey, field);
|
|
2559
|
-
}
|
|
2560
|
-
var nameKey = normalizeKey(field.field_path_name);
|
|
2561
|
-
if (nameKey && !fieldNameIndex.has(nameKey)) {
|
|
2562
|
-
fieldNameIndex.set(nameKey, field.field_path);
|
|
2563
|
-
}
|
|
2564
|
-
});
|
|
2565
|
-
return { collectionIndex: collectionIndex, fieldIndex: fieldIndex, fieldNameIndex: fieldNameIndex };
|
|
2566
|
-
}
|
|
2567
|
-
function sanitizeReportBuilderPatch(raw, ctx) {
|
|
2568
|
-
var patch = {};
|
|
2569
|
-
if (!raw || typeof raw !== 'object') {
|
|
2570
|
-
return patch;
|
|
2571
|
-
}
|
|
2572
|
-
var reportName = normalizeOptionalString(raw.report_name || raw.reportName || raw.title);
|
|
2573
|
-
if (reportName) {
|
|
2574
|
-
patch.report_name = reportName.slice(0, 120);
|
|
2575
|
-
}
|
|
2576
|
-
var collectionRoot = resolveCollectionName(raw.collection_root || raw.collectionRoot, ctx);
|
|
2577
|
-
if (collectionRoot) {
|
|
2578
|
-
patch.collection_root = collectionRoot;
|
|
2579
|
-
}
|
|
2580
|
-
var joinsRaw = Array.isArray(raw.collection_joins || raw.joins) ? (raw.collection_joins || raw.joins) : [];
|
|
2581
|
-
var joins = [];
|
|
2582
|
-
joinsRaw.forEach(function (join) {
|
|
2583
|
-
var collection = resolveCollectionName((join === null || join === void 0 ? void 0 : join.collection) || (join === null || join === void 0 ? void 0 : join.name), ctx);
|
|
2584
|
-
if (!collection) {
|
|
2585
|
-
return;
|
|
2586
|
-
}
|
|
2587
|
-
var alias = sanitizeAlias(join === null || join === void 0 ? void 0 : join.alias);
|
|
2588
|
-
joins.push(__assign({ collection: collection }, (alias ? { alias: alias } : {})));
|
|
2589
|
-
});
|
|
2590
|
-
if (joins.length) {
|
|
2591
|
-
patch.collection_joins = joins;
|
|
2592
|
-
}
|
|
2593
|
-
var layoutColumnsRaw = Array.isArray(raw.layout_columns || raw.columns || raw.layout) ? (raw.layout_columns || raw.columns || raw.layout) : [];
|
|
2594
|
-
var layoutColumns = [];
|
|
2595
|
-
layoutColumnsRaw.forEach(function (col) {
|
|
2596
|
-
if (!col || typeof col !== 'object') {
|
|
2597
|
-
return;
|
|
2598
|
-
}
|
|
2599
|
-
var header = normalizeOptionalString(col.header || col.title || col.name);
|
|
2600
|
-
var fieldPath = resolveFieldPath(col.field_path || col.fieldPath || col.field || col.field_name || col.fieldName || col.path, ctx);
|
|
2601
|
-
if (!fieldPath && header) {
|
|
2602
|
-
fieldPath = resolveFieldPath(header, ctx);
|
|
2603
|
-
}
|
|
2604
|
-
var mappingsRaw = Array.isArray(col.mappings) ? col.mappings : [];
|
|
2605
|
-
var mappings = [];
|
|
2606
|
-
mappingsRaw.forEach(function (map) {
|
|
2607
|
-
var mappedField = resolveFieldPath((map === null || map === void 0 ? void 0 : map.field_path) || (map === null || map === void 0 ? void 0 : map.fieldPath) || (map === null || map === void 0 ? void 0 : map.field) || (map === null || map === void 0 ? void 0 : map.field_name) || (map === null || map === void 0 ? void 0 : map.fieldName) || (map === null || map === void 0 ? void 0 : map.path) || (map === null || map === void 0 ? void 0 : map.name), ctx);
|
|
2608
|
-
var mode = normalizeLayoutMode(map === null || map === void 0 ? void 0 : map.mode);
|
|
2609
|
-
var text = normalizeOptionalString(map === null || map === void 0 ? void 0 : map.text);
|
|
2610
|
-
var collection = resolveCollectionName(map === null || map === void 0 ? void 0 : map.collection, ctx);
|
|
2611
|
-
if (mode === 'text') {
|
|
2612
|
-
if (text) {
|
|
2613
|
-
mappings.push({
|
|
2614
|
-
mode: mode,
|
|
2615
|
-
text: text,
|
|
2616
|
-
collection: collection
|
|
2617
|
-
});
|
|
2618
|
-
}
|
|
2619
|
-
}
|
|
2620
|
-
else if (mappedField) {
|
|
2621
|
-
mappings.push({
|
|
2622
|
-
mode: mode,
|
|
2623
|
-
field_path: mappedField,
|
|
2624
|
-
collection: collection,
|
|
2625
|
-
leaf_value_type: normalizeOptionalString((map === null || map === void 0 ? void 0 : map.leaf_value_type) || (map === null || map === void 0 ? void 0 : map.leafValueType)),
|
|
2626
|
-
leaf_format_type: normalizeOptionalString((map === null || map === void 0 ? void 0 : map.leaf_format_type) || (map === null || map === void 0 ? void 0 : map.leafFormatType)),
|
|
2627
|
-
show: typeof (map === null || map === void 0 ? void 0 : map.show) === 'boolean' ? map.show : undefined
|
|
2628
|
-
});
|
|
2629
|
-
}
|
|
2630
|
-
});
|
|
2631
|
-
if (!mappings.length) {
|
|
2632
|
-
if (fieldPath) {
|
|
2633
|
-
mappings.push({ field_path: fieldPath, mode: normalizeLayoutMode(col.mode) });
|
|
2634
|
-
}
|
|
2635
|
-
else {
|
|
2636
|
-
var text = normalizeOptionalString(col.text);
|
|
2637
|
-
var mode = normalizeLayoutMode(col.mode);
|
|
2638
|
-
if ((mode === 'text' || text) && text) {
|
|
2639
|
-
mappings.push({
|
|
2640
|
-
mode: 'text',
|
|
2641
|
-
text: text,
|
|
2642
|
-
collection: resolveCollectionName(col.collection, ctx)
|
|
2643
|
-
});
|
|
2644
|
-
}
|
|
2645
|
-
}
|
|
2646
|
-
}
|
|
2647
|
-
if (!fieldPath) {
|
|
2648
|
-
var firstMapped = mappings.find(function (mapping) { return !!(mapping === null || mapping === void 0 ? void 0 : mapping.field_path); });
|
|
2649
|
-
if (firstMapped === null || firstMapped === void 0 ? void 0 : firstMapped.field_path) {
|
|
2650
|
-
fieldPath = firstMapped.field_path;
|
|
2651
|
-
}
|
|
2652
|
-
}
|
|
2653
|
-
if (!header && fieldPath) {
|
|
2654
|
-
var meta = ctx.fieldIndex.get(normalizePathKey(fieldPath));
|
|
2655
|
-
header = normalizeOptionalString(meta === null || meta === void 0 ? void 0 : meta.field_path_name);
|
|
2656
|
-
}
|
|
2657
|
-
if (!mappings.length) {
|
|
2658
|
-
return;
|
|
2659
|
-
}
|
|
2660
|
-
layoutColumns.push({
|
|
2661
|
-
header: header || '',
|
|
2662
|
-
field_path: fieldPath || '',
|
|
2663
|
-
collection: resolveCollectionName(col.collection, ctx),
|
|
2664
|
-
mode: normalizeLayoutMode(col.mode),
|
|
2665
|
-
text: normalizeOptionalString(col.text),
|
|
2666
|
-
mappings: mappings
|
|
2667
|
-
});
|
|
2668
|
-
});
|
|
2669
|
-
if (!layoutColumns.length && Array.isArray(raw.selected_fields)) {
|
|
2670
|
-
(raw.selected_fields || []).forEach(function (field) {
|
|
2671
|
-
var fieldPath = resolveFieldPath(field, ctx);
|
|
2672
|
-
if (!fieldPath) {
|
|
2673
|
-
return;
|
|
2674
|
-
}
|
|
2675
|
-
layoutColumns.push({
|
|
2676
|
-
header: '',
|
|
2677
|
-
field_path: fieldPath,
|
|
2678
|
-
mappings: [{ field_path: fieldPath }]
|
|
2679
|
-
});
|
|
2680
|
-
});
|
|
2681
|
-
}
|
|
2682
|
-
if (layoutColumns.length) {
|
|
2683
|
-
patch.layout_columns = layoutColumns;
|
|
2684
|
-
}
|
|
2685
|
-
var groupsRowRaw = Array.isArray(raw.groups_row) ? raw.groups_row : [];
|
|
2686
|
-
var groupsRow = groupsRowRaw.map(function (entry) { return resolveFieldPath(entry, ctx); }).filter(Boolean);
|
|
2687
|
-
if (groupsRow.length) {
|
|
2688
|
-
patch.groups_row = groupsRow;
|
|
2689
|
-
}
|
|
2690
|
-
var filtersRaw = Array.isArray(raw.filters) ? raw.filters : [];
|
|
2691
|
-
var filters = [];
|
|
2692
|
-
filtersRaw.forEach(function (filter) {
|
|
2693
|
-
var fieldPath = resolveFieldPath((filter === null || filter === void 0 ? void 0 : filter.field_path) || (filter === null || filter === void 0 ? void 0 : filter.fieldPath), ctx);
|
|
2694
|
-
if (!fieldPath) {
|
|
2695
|
-
return;
|
|
2696
|
-
}
|
|
2697
|
-
var fieldMeta = ctx.fieldIndex.get(normalizePathKey(fieldPath));
|
|
2698
|
-
var condition = normalizeFilterCondition(filter === null || filter === void 0 ? void 0 : filter.condition);
|
|
2699
|
-
if (!condition) {
|
|
2700
|
-
return;
|
|
2701
|
-
}
|
|
2702
|
-
var value = normalizeFilterValue(filter === null || filter === void 0 ? void 0 : filter.value, fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.field_type);
|
|
2703
|
-
var highValue = normalizeFilterValue(filter === null || filter === void 0 ? void 0 : filter.high_value, fieldMeta === null || fieldMeta === void 0 ? void 0 : fieldMeta.field_type);
|
|
2704
|
-
var booleanValue = normalizeBooleanValue(filter === null || filter === void 0 ? void 0 : filter.boolean_value);
|
|
2705
|
-
filters.push({
|
|
2706
|
-
field_path: fieldPath,
|
|
2707
|
-
condition: condition,
|
|
2708
|
-
value: value,
|
|
2709
|
-
high_value: highValue,
|
|
2710
|
-
boolean_value: booleanValue,
|
|
2711
|
-
is_rolling: typeof (filter === null || filter === void 0 ? void 0 : filter.is_rolling) === 'boolean' ? filter.is_rolling : undefined,
|
|
2712
|
-
rolling_interval: normalizeOptionalString(filter === null || filter === void 0 ? void 0 : filter.rolling_interval)
|
|
2713
|
-
});
|
|
2714
|
-
});
|
|
2715
|
-
if (filters.length) {
|
|
2716
|
-
patch.filters = filters;
|
|
2717
|
-
}
|
|
2718
|
-
var sortRaw = Array.isArray(raw.sort) ? raw.sort : [];
|
|
2719
|
-
var sort = [];
|
|
2720
|
-
sortRaw.forEach(function (entry) {
|
|
2721
|
-
var fieldPath = resolveFieldPath((entry === null || entry === void 0 ? void 0 : entry.field_path) || (entry === null || entry === void 0 ? void 0 : entry.fieldPath), ctx);
|
|
2722
|
-
if (!fieldPath) {
|
|
2723
|
-
return;
|
|
2724
|
-
}
|
|
2725
|
-
sort.push({
|
|
2726
|
-
field_path: fieldPath,
|
|
2727
|
-
order: normalizeSortOrder(entry === null || entry === void 0 ? void 0 : entry.order)
|
|
2728
|
-
});
|
|
2729
|
-
});
|
|
2730
|
-
if (sort.length) {
|
|
2731
|
-
patch.sort = sort;
|
|
2732
|
-
}
|
|
2733
|
-
else {
|
|
2734
|
-
var defaultSortFields = buildDefaultSortFields(groupsRow, layoutColumns);
|
|
2735
|
-
if (defaultSortFields.length) {
|
|
2736
|
-
patch.sort = defaultSortFields.map(function (field_path) { return ({ field_path: field_path, order: 'asc' }); });
|
|
2737
|
-
}
|
|
2738
|
-
}
|
|
2739
|
-
var totalsRaw = Array.isArray(raw.totals) ? raw.totals : [];
|
|
2740
|
-
var totals = [];
|
|
2741
|
-
totalsRaw.forEach(function (total) {
|
|
2742
|
-
var type = normalizeTotalType(total === null || total === void 0 ? void 0 : total.type);
|
|
2743
|
-
var fields = Array.isArray(total === null || total === void 0 ? void 0 : total.fields) ? total.fields : [];
|
|
2744
|
-
var mappedFields = fields.map(function (field) { return resolveFieldPath(field, ctx); }).filter(Boolean);
|
|
2745
|
-
if (!type || !mappedFields.length) {
|
|
2746
|
-
return;
|
|
2747
|
-
}
|
|
2748
|
-
totals.push({ type: type, fields: mappedFields });
|
|
2749
|
-
});
|
|
2750
|
-
if (totals.length) {
|
|
2751
|
-
patch.totals = totals;
|
|
2752
|
-
}
|
|
2753
|
-
var linksRaw = Array.isArray(raw.links) ? raw.links : [];
|
|
2754
|
-
var links = [];
|
|
2755
|
-
linksRaw.forEach(function (link) {
|
|
2756
|
-
var first = resolveFieldPath((link === null || link === void 0 ? void 0 : link.field_first) || (link === null || link === void 0 ? void 0 : link.fieldFirst), ctx);
|
|
2757
|
-
var second = resolveFieldPath((link === null || link === void 0 ? void 0 : link.field_second) || (link === null || link === void 0 ? void 0 : link.fieldSecond), ctx);
|
|
2758
|
-
if (!first || !second) {
|
|
2759
|
-
return;
|
|
2760
|
-
}
|
|
2761
|
-
links.push({ field_first: first, field_second: second });
|
|
2762
|
-
});
|
|
2763
|
-
if (links.length) {
|
|
2764
|
-
patch.links = links;
|
|
2765
|
-
}
|
|
2766
|
-
var dateField = resolveFieldPath(raw.id_date_field || raw.date_field || raw.dateField, ctx);
|
|
2767
|
-
if (dateField) {
|
|
2768
|
-
patch.id_date_field = dateField;
|
|
2769
|
-
}
|
|
2770
|
-
var dateInterval = normalizeDateInterval(raw.date_interval || raw.dateInterval);
|
|
2771
|
-
if (dateInterval) {
|
|
2772
|
-
patch.date_interval = dateInterval;
|
|
2773
|
-
}
|
|
2774
|
-
var notes = normalizeOptionalString(raw.notes || raw.summary || raw.message);
|
|
2775
|
-
if (notes) {
|
|
2776
|
-
patch.notes = notes.slice(0, 400);
|
|
2777
|
-
}
|
|
2778
|
-
return patch;
|
|
2779
|
-
}
|
|
2780
|
-
function buildDefaultSortFields(groupsRow, layoutColumns) {
|
|
2781
|
-
var fields = [];
|
|
2782
|
-
var addField = function (fieldPath) {
|
|
2783
|
-
var normalized = normalizeOptionalString(fieldPath);
|
|
2784
|
-
if (normalized && !fields.includes(normalized)) {
|
|
2785
|
-
fields.push(normalized);
|
|
2786
|
-
}
|
|
2787
|
-
};
|
|
2788
|
-
(groupsRow || []).forEach(addField);
|
|
2789
|
-
if (fields.length) {
|
|
2790
|
-
return fields;
|
|
2791
|
-
}
|
|
2792
|
-
(layoutColumns || []).forEach(function (col) {
|
|
2793
|
-
var e_3, _a;
|
|
2794
|
-
if (!col || typeof col !== 'object') {
|
|
2795
|
-
return;
|
|
2796
|
-
}
|
|
2797
|
-
var fieldPath = '';
|
|
2798
|
-
var mappings = Array.isArray(col.mappings) ? col.mappings : [];
|
|
2799
|
-
try {
|
|
2800
|
-
for (var mappings_1 = __values(mappings), mappings_1_1 = mappings_1.next(); !mappings_1_1.done; mappings_1_1 = mappings_1.next()) {
|
|
2801
|
-
var mapping = mappings_1_1.value;
|
|
2802
|
-
if (mapping === null || mapping === void 0 ? void 0 : mapping.field_path) {
|
|
2803
|
-
fieldPath = mapping.field_path;
|
|
2804
|
-
break;
|
|
2805
|
-
}
|
|
2806
|
-
}
|
|
2807
|
-
}
|
|
2808
|
-
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
2809
|
-
finally {
|
|
2810
|
-
try {
|
|
2811
|
-
if (mappings_1_1 && !mappings_1_1.done && (_a = mappings_1.return)) _a.call(mappings_1);
|
|
2812
|
-
}
|
|
2813
|
-
finally { if (e_3) throw e_3.error; }
|
|
2814
|
-
}
|
|
2815
|
-
if (!fieldPath && col.field_path) {
|
|
2816
|
-
fieldPath = col.field_path;
|
|
2817
|
-
}
|
|
2818
|
-
addField(fieldPath);
|
|
2819
|
-
});
|
|
2820
|
-
return fields;
|
|
2821
|
-
}
|
|
2822
|
-
function buildPatchNotes(patch, meta) {
|
|
2823
|
-
var columns = Array.isArray(patch === null || patch === void 0 ? void 0 : patch.layout_columns) ? patch.layout_columns.length : 0;
|
|
2824
|
-
var groups = Array.isArray(patch === null || patch === void 0 ? void 0 : patch.groups_row) ? patch.groups_row.length : 0;
|
|
2825
|
-
var filters = Array.isArray(patch === null || patch === void 0 ? void 0 : patch.filters) ? patch.filters.length : 0;
|
|
2826
|
-
var joins = Array.isArray(patch === null || patch === void 0 ? void 0 : patch.collection_joins) ? patch.collection_joins.length : 0;
|
|
2827
|
-
var parts = [
|
|
2828
|
-
"AI suggested ".concat(columns, " column").concat(columns === 1 ? '' : 's'),
|
|
2829
|
-
groups ? "".concat(groups, " group").concat(groups === 1 ? '' : 's') : '',
|
|
2830
|
-
filters ? "".concat(filters, " filter").concat(filters === 1 ? '' : 's') : '',
|
|
2831
|
-
joins ? "".concat(joins, " join").concat(joins === 1 ? '' : 's') : ''
|
|
2832
|
-
].filter(Boolean);
|
|
2833
|
-
var note = parts.length ? parts.join(', ') + '.' : 'AI suggestions ready.';
|
|
2834
|
-
if (patch === null || patch === void 0 ? void 0 : patch.notes) {
|
|
2835
|
-
note += " ".concat(patch.notes);
|
|
2836
|
-
}
|
|
2837
|
-
if (meta.inferenceReason) {
|
|
2838
|
-
note += " ".concat(meta.inferenceReason);
|
|
2839
|
-
}
|
|
2840
|
-
if (meta.truncated) {
|
|
2841
|
-
note += " Field list trimmed to ".concat(meta.usedFields, " of ").concat(meta.totalFields, " available fields.");
|
|
2842
|
-
}
|
|
2843
|
-
return note;
|
|
2844
|
-
}
|
|
2845
|
-
function normalizeLayoutMode(value) {
|
|
2846
|
-
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
2847
|
-
return normalized === 'text' ? 'text' : 'variable';
|
|
2848
|
-
}
|
|
2849
|
-
function normalizeFilterCondition(value) {
|
|
2850
|
-
var allowed = new Set(['eq', 'ne', 'lt', 'lte', 'gt', 'gte', 'bw', 'nnull', 'null', 'regex']);
|
|
2851
|
-
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
2852
|
-
return allowed.has(normalized) ? normalized : '';
|
|
2853
|
-
}
|
|
2854
|
-
function normalizeSortOrder(value) {
|
|
2855
|
-
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
2856
|
-
return normalized === 'dsc' || normalized === 'desc' ? 'dsc' : 'asc';
|
|
2857
|
-
}
|
|
2858
|
-
function normalizeTotalType(value) {
|
|
2859
|
-
var normalized = normalizeOptionalString(value).toLowerCase();
|
|
2860
|
-
if (normalized === 'avg' || normalized === 'sum') {
|
|
2861
|
-
return normalized;
|
|
2862
|
-
}
|
|
2863
|
-
return '';
|
|
2864
|
-
}
|
|
2865
|
-
function normalizeDateInterval(value) {
|
|
2866
|
-
var normalized = normalizeOptionalString(value);
|
|
2867
|
-
if (!normalized) {
|
|
2868
|
-
return '';
|
|
2869
|
-
}
|
|
2870
|
-
var map = {
|
|
2871
|
-
seconds: 'Seconds',
|
|
2872
|
-
minutes: 'Minutes',
|
|
2873
|
-
hours: 'Hours',
|
|
2874
|
-
daily: 'Daily',
|
|
2875
|
-
weekly: 'Weekly',
|
|
2876
|
-
monthly: 'Monthly',
|
|
2877
|
-
quarterly: 'Quarterly',
|
|
2878
|
-
yearly: 'Yearly'
|
|
2879
|
-
};
|
|
2880
|
-
var key = normalized.toLowerCase();
|
|
2881
|
-
return map[key] || '';
|
|
2882
|
-
}
|
|
2883
|
-
function normalizeFilterValue(value, fieldType) {
|
|
2884
|
-
if (fieldType === 'Number') {
|
|
2885
|
-
var num = Number(value);
|
|
2886
|
-
return Number.isFinite(num) ? num : value;
|
|
2887
|
-
}
|
|
2888
|
-
if (fieldType === 'Boolean') {
|
|
2889
|
-
if (value === true || value === false) {
|
|
2890
|
-
return value;
|
|
2891
|
-
}
|
|
2892
|
-
if (typeof value === 'string') {
|
|
2893
|
-
return value.toLowerCase() === 'true';
|
|
2894
|
-
}
|
|
2895
|
-
return value;
|
|
2896
|
-
}
|
|
2897
|
-
if (fieldType === 'Date') {
|
|
2898
|
-
if (value instanceof Date) {
|
|
2899
|
-
return value;
|
|
2900
|
-
}
|
|
2901
|
-
if (typeof value === 'string') {
|
|
2902
|
-
var parsed = new Date(value);
|
|
2903
|
-
return isNaN(parsed.getTime()) ? value : parsed.toISOString();
|
|
2904
|
-
}
|
|
2905
|
-
}
|
|
2906
|
-
return value;
|
|
2907
|
-
}
|
|
2908
|
-
function normalizeBooleanValue(value) {
|
|
2909
|
-
if (value === true || value === false) {
|
|
2910
|
-
return value;
|
|
2911
|
-
}
|
|
2912
|
-
if (typeof value === 'string') {
|
|
2913
|
-
if (value.toLowerCase() === 'true') {
|
|
2914
|
-
return true;
|
|
2915
|
-
}
|
|
2916
|
-
if (value.toLowerCase() === 'false') {
|
|
2917
|
-
return false;
|
|
2918
|
-
}
|
|
2919
|
-
}
|
|
2920
|
-
return undefined;
|
|
2921
|
-
}
|
|
2922
|
-
function resolveCollectionName(value, ctx) {
|
|
2923
|
-
var key = normalizeKey(value);
|
|
2924
|
-
if (!key) {
|
|
2925
|
-
return '';
|
|
2926
|
-
}
|
|
2927
|
-
var found = ctx.collectionIndex.get(key);
|
|
2928
|
-
return found ? found.collection : '';
|
|
2929
|
-
}
|
|
2930
|
-
function resolveFieldPath(value, ctx) {
|
|
2931
|
-
var _a;
|
|
2932
|
-
var pathKey = normalizePathKey(value);
|
|
2933
|
-
if (pathKey && ctx.fieldIndex.has(pathKey)) {
|
|
2934
|
-
return ((_a = ctx.fieldIndex.get(pathKey)) === null || _a === void 0 ? void 0 : _a.field_path) || '';
|
|
2935
|
-
}
|
|
2936
|
-
var nameKey = normalizeKey(value);
|
|
2937
|
-
if (nameKey && ctx.fieldNameIndex.has(nameKey)) {
|
|
2938
|
-
return ctx.fieldNameIndex.get(nameKey) || '';
|
|
2939
|
-
}
|
|
2940
|
-
return '';
|
|
2941
|
-
}
|
|
2942
|
-
function sanitizeAlias(value) {
|
|
2943
|
-
var alias = normalizeOptionalString(value);
|
|
2944
|
-
if (!alias) {
|
|
2945
|
-
return '';
|
|
2946
|
-
}
|
|
2947
|
-
return alias.replace(/[^\w\- ]/g, '').trim().slice(0, 40);
|
|
2948
|
-
}
|
|
2949
|
-
function normalizeKey(value) {
|
|
2950
|
-
return normalizeOptionalString(value).toLowerCase().replace(/[^a-z0-9]+/g, '');
|
|
2951
|
-
}
|
|
2952
|
-
function normalizePathKey(value) {
|
|
2953
|
-
return normalizeOptionalString(value).toLowerCase();
|
|
2954
|
-
}
|
|
2955
|
-
function resolveArrayRoot(path) {
|
|
2956
|
-
var raw = normalizeOptionalString(path);
|
|
2957
|
-
if (!raw) {
|
|
2958
|
-
return '';
|
|
2959
|
-
}
|
|
2960
|
-
var idx = raw.indexOf('.$');
|
|
2961
|
-
if (idx === -1) {
|
|
2962
|
-
return '';
|
|
2963
|
-
}
|
|
2964
|
-
return raw.slice(0, idx);
|
|
2965
|
-
}
|
|
2966
|
-
function isLinkCandidateFieldPath(path) {
|
|
2967
|
-
var normalized = normalizeOptionalString(path).toLowerCase();
|
|
2968
|
-
if (!normalized) {
|
|
2969
|
-
return false;
|
|
2970
|
-
}
|
|
2971
|
-
var last = (normalized.split('.').pop() || '').replace(/\$/g, '');
|
|
2972
|
-
if (!last) {
|
|
2973
|
-
return false;
|
|
2974
|
-
}
|
|
2975
|
-
if (last === 'id' || last === '_id') {
|
|
2976
|
-
return true;
|
|
2977
|
-
}
|
|
2978
|
-
if (last.endsWith('_id') || last.endsWith('_uuid') || last.endsWith('_guid')) {
|
|
2979
|
-
return true;
|
|
2980
|
-
}
|
|
2981
|
-
if (last.startsWith('id_')) {
|
|
2982
|
-
return true;
|
|
2983
|
-
}
|
|
2984
|
-
return false;
|
|
2985
|
-
}
|
|
2986
|
-
function safeJsonParse(value) {
|
|
2987
|
-
if (!value) {
|
|
2988
|
-
return null;
|
|
2989
|
-
}
|
|
2990
|
-
try {
|
|
2991
|
-
return JSON.parse(value);
|
|
2992
|
-
}
|
|
2993
|
-
catch (_a) {
|
|
2994
|
-
var match = value.match(/\{[\s\S]*\}/);
|
|
2995
|
-
if (!match) {
|
|
2996
|
-
return null;
|
|
2997
|
-
}
|
|
2998
|
-
try {
|
|
2999
|
-
return JSON.parse(match[0]);
|
|
3000
|
-
}
|
|
3001
|
-
catch (_b) {
|
|
3002
|
-
return null;
|
|
3003
|
-
}
|
|
3004
|
-
}
|
|
3005
|
-
}
|
|
3006
|
-
function evaluateReportBuilderGuardrails(message) {
|
|
3007
|
-
var e_4, _a;
|
|
3008
|
-
var normalized = String(message || '').toLowerCase();
|
|
3009
|
-
var patterns = [
|
|
3010
|
-
{ pattern: /\b(source\s*code|full\s*code|entire\s*code|repo\s*dump|repository|git\s*clone)\b/i, reason: 'Code access is restricted.' },
|
|
3011
|
-
{ pattern: /\b(credentials?|passwords?|secrets?|tokens?)\b/i, reason: 'Credentials and secrets are restricted.' },
|
|
3012
|
-
{ pattern: /\b(delete|drop|truncate)\s+(database|db|schema|table)\b/i, reason: 'Database operations are restricted.' },
|
|
3013
|
-
{ pattern: /\b(shell|terminal|ssh|sudo|rm\s+-rf|chmod|chown)\b/i, reason: 'Server operations are restricted.' },
|
|
3014
|
-
{ pattern: /\b(exploit|bypass|malware|phishing|ransomware|ddos|sql\s*injection)\b/i, reason: 'Security abuse is restricted.' },
|
|
3015
|
-
{ pattern: /\b(credit\s*card|social\s*security|ssn|bank\s*account)\b/i, reason: 'Sensitive personal data is restricted.' }
|
|
3016
|
-
];
|
|
3017
|
-
try {
|
|
3018
|
-
for (var patterns_1 = __values(patterns), patterns_1_1 = patterns_1.next(); !patterns_1_1.done; patterns_1_1 = patterns_1.next()) {
|
|
3019
|
-
var entry = patterns_1_1.value;
|
|
3020
|
-
if (entry.pattern.test(normalized)) {
|
|
3021
|
-
return {
|
|
3022
|
-
blocked: true,
|
|
3023
|
-
reason: entry.reason,
|
|
3024
|
-
response: 'I can’t help with that request because it could access restricted systems or data. Please describe the report you need (fields, filters, timeframe) and I can configure it safely.'
|
|
3025
|
-
};
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
}
|
|
3029
|
-
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
3030
|
-
finally {
|
|
3031
|
-
try {
|
|
3032
|
-
if (patterns_1_1 && !patterns_1_1.done && (_a = patterns_1.return)) _a.call(patterns_1);
|
|
3033
|
-
}
|
|
3034
|
-
finally { if (e_4) throw e_4.error; }
|
|
3035
|
-
}
|
|
3036
|
-
return null;
|
|
3037
|
-
}
|
|
3038
|
-
function resolveIsSuperAdmin(id_user) {
|
|
3039
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3040
|
-
var user, _a;
|
|
3041
|
-
var _b;
|
|
3042
|
-
return __generator(this, function (_c) {
|
|
3043
|
-
switch (_c.label) {
|
|
3044
|
-
case 0:
|
|
3045
|
-
if (!id_user) {
|
|
3046
|
-
return [2 /*return*/, false];
|
|
3047
|
-
}
|
|
3048
|
-
_c.label = 1;
|
|
3049
|
-
case 1:
|
|
3050
|
-
_c.trys.push([1, 3, , 4]);
|
|
3051
|
-
return [4 /*yield*/, user_collection_1.Users.findById(id_user)];
|
|
3052
|
-
case 2:
|
|
3053
|
-
user = _c.sent();
|
|
3054
|
-
return [2 /*return*/, !!((_b = user === null || user === void 0 ? void 0 : user.roles) === null || _b === void 0 ? void 0 : _b.super_admin)];
|
|
3055
|
-
case 3:
|
|
3056
|
-
_a = _c.sent();
|
|
3057
|
-
return [2 /*return*/, false];
|
|
3058
|
-
case 4: return [2 /*return*/];
|
|
3059
|
-
}
|
|
3060
|
-
});
|
|
3061
|
-
});
|
|
3062
|
-
}
|
|
3063
|
-
function resolveClientId(idClientInput, idUser) {
|
|
3064
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
3065
|
-
var normalized, user, fromOther, _a;
|
|
3066
|
-
var _b, _c;
|
|
3067
|
-
return __generator(this, function (_d) {
|
|
3068
|
-
switch (_d.label) {
|
|
3069
|
-
case 0:
|
|
3070
|
-
normalized = normalizeOptionalString(idClientInput);
|
|
3071
|
-
if (normalized) {
|
|
3072
|
-
return [2 /*return*/, normalized];
|
|
3073
|
-
}
|
|
3074
|
-
if (!idUser) {
|
|
3075
|
-
return [2 /*return*/, ''];
|
|
3076
|
-
}
|
|
3077
|
-
_d.label = 1;
|
|
3078
|
-
case 1:
|
|
3079
|
-
_d.trys.push([1, 3, , 4]);
|
|
3080
|
-
return [4 /*yield*/, user_collection_1.Users.findById(idUser)];
|
|
3081
|
-
case 2:
|
|
3082
|
-
user = _d.sent();
|
|
3083
|
-
fromOther = normalizeOptionalString(((_b = user === null || user === void 0 ? void 0 : user.other) === null || _b === void 0 ? void 0 : _b.id_client) || ((_c = user === null || user === void 0 ? void 0 : user.other) === null || _c === void 0 ? void 0 : _c.idClient));
|
|
3084
|
-
return [2 /*return*/, fromOther];
|
|
3085
|
-
case 3:
|
|
3086
|
-
_a = _d.sent();
|
|
3087
|
-
return [2 /*return*/, ''];
|
|
3088
|
-
case 4: return [2 /*return*/];
|
|
3089
|
-
}
|
|
3090
|
-
});
|
|
3091
|
-
});
|
|
3092
|
-
}
|
|
3093
|
-
|
|
3094
|
-
//# sourceMappingURL=report-builder.js.map
|