@atproto/ozone 0.1.172 → 0.1.174
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/CHANGELOG.md +18 -0
- package/dist/api/index.d.ts.map +1 -1
- package/dist/api/index.js +40 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/moderation/emitEvent.d.ts.map +1 -1
- package/dist/api/moderation/emitEvent.js +31 -0
- package/dist/api/moderation/emitEvent.js.map +1 -1
- package/dist/api/queue/assignModerator.d.ts +4 -0
- package/dist/api/queue/assignModerator.d.ts.map +1 -0
- package/dist/api/queue/assignModerator.js +28 -0
- package/dist/api/queue/assignModerator.js.map +1 -0
- package/dist/api/queue/createQueue.d.ts +4 -0
- package/dist/api/queue/createQueue.d.ts.map +1 -0
- package/dist/api/queue/createQueue.js +44 -0
- package/dist/api/queue/createQueue.js.map +1 -0
- package/dist/api/queue/deleteQueue.d.ts +4 -0
- package/dist/api/queue/deleteQueue.d.ts.map +1 -0
- package/dist/api/queue/deleteQueue.js +40 -0
- package/dist/api/queue/deleteQueue.js.map +1 -0
- package/dist/api/queue/getAssignments.d.ts +4 -0
- package/dist/api/queue/getAssignments.d.ts.map +1 -0
- package/dist/api/queue/getAssignments.js +19 -0
- package/dist/api/queue/getAssignments.js.map +1 -0
- package/dist/api/queue/listQueues.d.ts +4 -0
- package/dist/api/queue/listQueues.d.ts.map +1 -0
- package/dist/api/queue/listQueues.js +29 -0
- package/dist/api/queue/listQueues.js.map +1 -0
- package/dist/api/queue/routeReports.d.ts +4 -0
- package/dist/api/queue/routeReports.d.ts.map +1 -0
- package/dist/api/queue/routeReports.js +33 -0
- package/dist/api/queue/routeReports.js.map +1 -0
- package/dist/api/queue/unassignModerator.d.ts +4 -0
- package/dist/api/queue/unassignModerator.d.ts.map +1 -0
- package/dist/api/queue/unassignModerator.js +24 -0
- package/dist/api/queue/unassignModerator.js.map +1 -0
- package/dist/api/queue/updateQueue.d.ts +4 -0
- package/dist/api/queue/updateQueue.d.ts.map +1 -0
- package/dist/api/queue/updateQueue.js +39 -0
- package/dist/api/queue/updateQueue.js.map +1 -0
- package/dist/api/report/assignModerator.d.ts +4 -0
- package/dist/api/report/assignModerator.d.ts.map +1 -0
- package/dist/api/report/assignModerator.js +33 -0
- package/dist/api/report/assignModerator.js.map +1 -0
- package/dist/api/report/createActivity.d.ts +4 -0
- package/dist/api/report/createActivity.d.ts.map +1 -0
- package/dist/api/report/createActivity.js +44 -0
- package/dist/api/report/createActivity.js.map +1 -0
- package/dist/api/report/getAssignments.d.ts +4 -0
- package/dist/api/report/getAssignments.d.ts.map +1 -0
- package/dist/api/report/getAssignments.js +19 -0
- package/dist/api/report/getAssignments.js.map +1 -0
- package/dist/api/report/getHistoricalStats.d.ts +4 -0
- package/dist/api/report/getHistoricalStats.d.ts.map +1 -0
- package/dist/api/report/getHistoricalStats.js +32 -0
- package/dist/api/report/getHistoricalStats.js.map +1 -0
- package/dist/api/report/getLatestReport.d.ts +4 -0
- package/dist/api/report/getLatestReport.d.ts.map +1 -0
- package/dist/api/report/getLatestReport.js +31 -0
- package/dist/api/report/getLatestReport.js.map +1 -0
- package/dist/api/report/getLiveStats.d.ts +4 -0
- package/dist/api/report/getLiveStats.d.ts.map +1 -0
- package/dist/api/report/getLiveStats.js +25 -0
- package/dist/api/report/getLiveStats.js.map +1 -0
- package/dist/api/report/getReport.d.ts +4 -0
- package/dist/api/report/getReport.d.ts.map +1 -0
- package/dist/api/report/getReport.js +35 -0
- package/dist/api/report/getReport.js.map +1 -0
- package/dist/api/report/listActivities.d.ts +4 -0
- package/dist/api/report/listActivities.d.ts.map +1 -0
- package/dist/api/report/listActivities.js +25 -0
- package/dist/api/report/listActivities.js.map +1 -0
- package/dist/api/report/queryReports.d.ts +4 -0
- package/dist/api/report/queryReports.d.ts.map +1 -0
- package/dist/api/report/queryReports.js +29 -0
- package/dist/api/report/queryReports.js.map +1 -0
- package/dist/api/report/reassignQueue.d.ts +4 -0
- package/dist/api/report/reassignQueue.d.ts.map +1 -0
- package/dist/api/report/reassignQueue.js +45 -0
- package/dist/api/report/reassignQueue.js.map +1 -0
- package/dist/api/report/refreshStats.d.ts +4 -0
- package/dist/api/report/refreshStats.d.ts.map +1 -0
- package/dist/api/report/refreshStats.js +26 -0
- package/dist/api/report/refreshStats.js.map +1 -0
- package/dist/api/report/unassignModerator.d.ts +4 -0
- package/dist/api/report/unassignModerator.d.ts.map +1 -0
- package/dist/api/report/unassignModerator.js +21 -0
- package/dist/api/report/unassignModerator.js.map +1 -0
- package/dist/api/util.d.ts +2 -0
- package/dist/api/util.d.ts.map +1 -1
- package/dist/api/util.js +9 -1
- package/dist/api/util.js.map +1 -1
- package/dist/assignment/index.d.ts +89 -0
- package/dist/assignment/index.d.ts.map +1 -0
- package/dist/assignment/index.js +537 -0
- package/dist/assignment/index.js.map +1 -0
- package/dist/config/config.d.ts +14 -0
- package/dist/config/config.d.ts.map +1 -1
- package/dist/config/config.js +9 -0
- package/dist/config/config.js.map +1 -1
- package/dist/config/env.d.ts +3 -0
- package/dist/config/env.d.ts.map +1 -1
- package/dist/config/env.js +3 -0
- package/dist/config/env.js.map +1 -1
- package/dist/context.d.ts +9 -0
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +31 -10
- package/dist/context.js.map +1 -1
- package/dist/daemon/context.d.ts +6 -0
- package/dist/daemon/context.d.ts.map +1 -1
- package/dist/daemon/context.js +28 -4
- package/dist/daemon/context.js.map +1 -1
- package/dist/daemon/event-reverser.d.ts +1 -0
- package/dist/daemon/event-reverser.d.ts.map +1 -1
- package/dist/daemon/event-reverser.js +42 -1
- package/dist/daemon/event-reverser.js.map +1 -1
- package/dist/daemon/job-cursor.d.ts +5 -0
- package/dist/daemon/job-cursor.d.ts.map +1 -0
- package/dist/daemon/job-cursor.js +28 -0
- package/dist/daemon/job-cursor.js.map +1 -0
- package/dist/daemon/queue-router.d.ts +17 -0
- package/dist/daemon/queue-router.d.ts.map +1 -0
- package/dist/daemon/queue-router.js +114 -0
- package/dist/daemon/queue-router.js.map +1 -0
- package/dist/daemon/stats-computer.d.ts +51 -0
- package/dist/daemon/stats-computer.d.ts.map +1 -0
- package/dist/daemon/stats-computer.js +117 -0
- package/dist/daemon/stats-computer.js.map +1 -0
- package/dist/daemon/strike-expiry-processor.d.ts.map +1 -1
- package/dist/daemon/strike-expiry-processor.js +4 -19
- package/dist/daemon/strike-expiry-processor.js.map +1 -1
- package/dist/db/migrations/20260219T164523000Z-create-report-table.d.ts +4 -0
- package/dist/db/migrations/20260219T164523000Z-create-report-table.d.ts.map +1 -0
- package/dist/db/migrations/20260219T164523000Z-create-report-table.js +126 -0
- package/dist/db/migrations/20260219T164523000Z-create-report-table.js.map +1 -0
- package/dist/db/migrations/20260219T165302248Z-moderator-assignment.d.ts +4 -0
- package/dist/db/migrations/20260219T165302248Z-moderator-assignment.d.ts.map +1 -0
- package/dist/db/migrations/20260219T165302248Z-moderator-assignment.js +35 -0
- package/dist/db/migrations/20260219T165302248Z-moderator-assignment.js.map +1 -0
- package/dist/db/migrations/20260225T000000000Z-add-report-queue-table.d.ts +4 -0
- package/dist/db/migrations/20260225T000000000Z-add-report-queue-table.d.ts.map +1 -0
- package/dist/db/migrations/20260225T000000000Z-add-report-queue-table.js +36 -0
- package/dist/db/migrations/20260225T000000000Z-add-report-queue-table.js.map +1 -0
- package/dist/db/migrations/20260313T000000000Z-add-report-activity-table.d.ts +4 -0
- package/dist/db/migrations/20260313T000000000Z-add-report-activity-table.d.ts.map +1 -0
- package/dist/db/migrations/20260313T000000000Z-add-report-activity-table.js +39 -0
- package/dist/db/migrations/20260313T000000000Z-add-report-activity-table.js.map +1 -0
- package/dist/db/migrations/20260318T152058935Z-add-report-stat.d.ts +4 -0
- package/dist/db/migrations/20260318T152058935Z-add-report-stat.d.ts.map +1 -0
- package/dist/db/migrations/20260318T152058935Z-add-report-stat.js +34 -0
- package/dist/db/migrations/20260318T152058935Z-add-report-stat.js.map +1 -0
- package/dist/db/migrations/20260428T000000000Z-add-expiring-tag-table.d.ts +4 -0
- package/dist/db/migrations/20260428T000000000Z-add-expiring-tag-table.d.ts.map +1 -0
- package/dist/db/migrations/20260428T000000000Z-add-expiring-tag-table.js +32 -0
- package/dist/db/migrations/20260428T000000000Z-add-expiring-tag-table.js.map +1 -0
- package/dist/db/migrations/index.d.ts +6 -0
- package/dist/db/migrations/index.d.ts.map +1 -1
- package/dist/db/migrations/index.js +7 -1
- package/dist/db/migrations/index.js.map +1 -1
- package/dist/db/pagination.d.ts +31 -0
- package/dist/db/pagination.d.ts.map +1 -1
- package/dist/db/pagination.js +74 -1
- package/dist/db/pagination.js.map +1 -1
- package/dist/db/schema/expiring_tag.d.ts +15 -0
- package/dist/db/schema/expiring_tag.d.ts.map +1 -0
- package/dist/db/schema/expiring_tag.js +5 -0
- package/dist/db/schema/expiring_tag.js.map +1 -0
- package/dist/db/schema/index.d.ts +7 -1
- package/dist/db/schema/index.d.ts.map +1 -1
- package/dist/db/schema/index.js.map +1 -1
- package/dist/db/schema/moderator_assignment.d.ts +14 -0
- package/dist/db/schema/moderator_assignment.d.ts.map +1 -0
- package/dist/db/schema/moderator_assignment.js +5 -0
- package/dist/db/schema/moderator_assignment.js.map +1 -0
- package/dist/db/schema/report.d.ts +25 -0
- package/dist/db/schema/report.d.ts.map +1 -0
- package/dist/db/schema/report.js +5 -0
- package/dist/db/schema/report.js.map +1 -0
- package/dist/db/schema/report_activity.d.ts +18 -0
- package/dist/db/schema/report_activity.d.ts.map +1 -0
- package/dist/db/schema/report_activity.js +5 -0
- package/dist/db/schema/report_activity.js.map +1 -0
- package/dist/db/schema/report_queue.d.ts +19 -0
- package/dist/db/schema/report_queue.d.ts.map +1 -0
- package/dist/db/schema/report_queue.js +5 -0
- package/dist/db/schema/report_queue.js.map +1 -0
- package/dist/db/schema/report_stat.d.ts +20 -0
- package/dist/db/schema/report_stat.d.ts.map +1 -0
- package/dist/db/schema/report_stat.js +5 -0
- package/dist/db/schema/report_stat.js.map +1 -0
- package/dist/lexicon/index.d.ts +50 -0
- package/dist/lexicon/index.d.ts.map +1 -1
- package/dist/lexicon/index.js +120 -2
- package/dist/lexicon/index.js.map +1 -1
- package/dist/lexicon/lexicons.d.ts +11255 -7885
- package/dist/lexicon/lexicons.d.ts.map +1 -1
- package/dist/lexicon/lexicons.js +1900 -120
- package/dist/lexicon/lexicons.js.map +1 -1
- package/dist/lexicon/types/app/bsky/embed/external.d.ts +2 -0
- package/dist/lexicon/types/app/bsky/embed/external.d.ts.map +1 -1
- package/dist/lexicon/types/app/bsky/embed/external.js.map +1 -1
- package/dist/lexicon/types/chat/bsky/actor/defs.d.ts +8 -2
- package/dist/lexicon/types/chat/bsky/actor/defs.d.ts.map +1 -1
- package/dist/lexicon/types/chat/bsky/actor/defs.js +9 -0
- package/dist/lexicon/types/chat/bsky/actor/defs.js.map +1 -1
- package/dist/lexicon/types/chat/bsky/convo/defs.d.ts +37 -10
- package/dist/lexicon/types/chat/bsky/convo/defs.d.ts.map +1 -1
- package/dist/lexicon/types/chat/bsky/convo/defs.js +9 -0
- package/dist/lexicon/types/chat/bsky/convo/defs.js.map +1 -1
- package/dist/lexicon/types/chat/bsky/convo/getMessages.d.ts +3 -0
- package/dist/lexicon/types/chat/bsky/convo/getMessages.d.ts.map +1 -1
- package/dist/lexicon/types/chat/bsky/convo/getMessages.js.map +1 -1
- package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts +2 -0
- package/dist/lexicon/types/tools/ozone/moderation/defs.d.ts.map +1 -1
- package/dist/lexicon/types/tools/ozone/moderation/defs.js.map +1 -1
- package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts +19 -0
- package/dist/lexicon/types/tools/ozone/moderation/emitEvent.d.ts.map +1 -1
- package/dist/lexicon/types/tools/ozone/moderation/emitEvent.js +9 -0
- package/dist/lexicon/types/tools/ozone/moderation/emitEvent.js.map +1 -1
- package/dist/lexicon/types/tools/ozone/queue/assignModerator.d.ts +27 -0
- package/dist/lexicon/types/tools/ozone/queue/assignModerator.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/assignModerator.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/assignModerator.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/createQueue.d.ts +35 -0
- package/dist/lexicon/types/tools/ozone/queue/createQueue.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/createQueue.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/createQueue.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/defs.d.ts +62 -0
- package/dist/lexicon/types/tools/ozone/queue/defs.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/defs.js +34 -0
- package/dist/lexicon/types/tools/ozone/queue/defs.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/deleteQueue.d.ts +29 -0
- package/dist/lexicon/types/tools/ozone/queue/deleteQueue.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/deleteQueue.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/deleteQueue.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/getAssignments.d.ts +30 -0
- package/dist/lexicon/types/tools/ozone/queue/getAssignments.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/getAssignments.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/getAssignments.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/listQueues.d.ts +32 -0
- package/dist/lexicon/types/tools/ozone/queue/listQueues.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/listQueues.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/listQueues.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/routeReports.d.ts +31 -0
- package/dist/lexicon/types/tools/ozone/queue/routeReports.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/routeReports.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/routeReports.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/unassignModerator.d.ts +18 -0
- package/dist/lexicon/types/tools/ozone/queue/unassignModerator.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/unassignModerator.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/unassignModerator.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/updateQueue.d.ts +32 -0
- package/dist/lexicon/types/tools/ozone/queue/updateQueue.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/queue/updateQueue.js +7 -0
- package/dist/lexicon/types/tools/ozone/queue/updateQueue.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/assignModerator.d.ts +31 -0
- package/dist/lexicon/types/tools/ozone/report/assignModerator.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/assignModerator.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/assignModerator.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/createActivity.d.ts +37 -0
- package/dist/lexicon/types/tools/ozone/report/createActivity.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/createActivity.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/createActivity.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/defs.d.ts +185 -0
- package/dist/lexicon/types/tools/ozone/report/defs.d.ts.map +1 -1
- package/dist/lexicon/types/tools/ozone/report/defs.js +108 -0
- package/dist/lexicon/types/tools/ozone/report/defs.js.map +1 -1
- package/dist/lexicon/types/tools/ozone/report/getAssignments.d.ts +30 -0
- package/dist/lexicon/types/tools/ozone/report/getAssignments.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getAssignments.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/getAssignments.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getHistoricalStats.d.ts +36 -0
- package/dist/lexicon/types/tools/ozone/report/getHistoricalStats.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getHistoricalStats.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/getHistoricalStats.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getLatestReport.d.ts +21 -0
- package/dist/lexicon/types/tools/ozone/report/getLatestReport.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getLatestReport.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/getLatestReport.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getLiveStats.d.ts +27 -0
- package/dist/lexicon/types/tools/ozone/report/getLiveStats.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getLiveStats.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/getLiveStats.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getReport.d.ts +22 -0
- package/dist/lexicon/types/tools/ozone/report/getReport.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/getReport.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/getReport.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/listActivities.d.ts +26 -0
- package/dist/lexicon/types/tools/ozone/report/listActivities.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/listActivities.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/listActivities.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/queryReports.d.ts +48 -0
- package/dist/lexicon/types/tools/ozone/report/queryReports.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/queryReports.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/queryReports.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/reassignQueue.d.ts +31 -0
- package/dist/lexicon/types/tools/ozone/report/reassignQueue.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/reassignQueue.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/reassignQueue.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/refreshStats.d.ts +28 -0
- package/dist/lexicon/types/tools/ozone/report/refreshStats.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/refreshStats.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/refreshStats.js.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/unassignModerator.d.ts +25 -0
- package/dist/lexicon/types/tools/ozone/report/unassignModerator.d.ts.map +1 -0
- package/dist/lexicon/types/tools/ozone/report/unassignModerator.js +7 -0
- package/dist/lexicon/types/tools/ozone/report/unassignModerator.js.map +1 -0
- package/dist/mod-service/expiring-tags.d.ts +27 -0
- package/dist/mod-service/expiring-tags.d.ts.map +1 -0
- package/dist/mod-service/expiring-tags.js +62 -0
- package/dist/mod-service/expiring-tags.js.map +1 -0
- package/dist/mod-service/index.d.ts +3 -1
- package/dist/mod-service/index.d.ts.map +1 -1
- package/dist/mod-service/index.js +61 -2
- package/dist/mod-service/index.js.map +1 -1
- package/dist/mod-service/report.d.ts +64 -0
- package/dist/mod-service/report.d.ts.map +1 -0
- package/dist/mod-service/report.js +282 -0
- package/dist/mod-service/report.js.map +1 -0
- package/dist/mod-service/status.d.ts +24 -0
- package/dist/mod-service/status.d.ts.map +1 -1
- package/dist/queue/service.d.ts +86 -0
- package/dist/queue/service.d.ts.map +1 -0
- package/dist/queue/service.js +430 -0
- package/dist/queue/service.js.map +1 -0
- package/dist/report/activity.d.ts +77 -0
- package/dist/report/activity.d.ts.map +1 -0
- package/dist/report/activity.js +141 -0
- package/dist/report/activity.js.map +1 -0
- package/dist/report/handle-report-update.d.ts +47 -0
- package/dist/report/handle-report-update.d.ts.map +1 -0
- package/dist/report/handle-report-update.js +178 -0
- package/dist/report/handle-report-update.js.map +1 -0
- package/dist/report/reassign.d.ts +10 -0
- package/dist/report/reassign.d.ts.map +1 -0
- package/dist/report/reassign.js +75 -0
- package/dist/report/reassign.js.map +1 -0
- package/dist/report/stats.d.ts +105 -0
- package/dist/report/stats.d.ts.map +1 -0
- package/dist/report/stats.js +619 -0
- package/dist/report/stats.js.map +1 -0
- package/dist/report/views.d.ts +111 -0
- package/dist/report/views.d.ts.map +1 -0
- package/dist/report/views.js +156 -0
- package/dist/report/views.js.map +1 -0
- package/dist/team/index.d.ts +1 -0
- package/dist/team/index.d.ts.map +1 -1
- package/dist/team/index.js +11 -0
- package/dist/team/index.js.map +1 -1
- package/package.json +3 -3
- package/src/api/index.ts +40 -0
- package/src/api/moderation/emitEvent.ts +38 -0
- package/src/api/queue/assignModerator.ts +31 -0
- package/src/api/queue/createQueue.ts +62 -0
- package/src/api/queue/deleteQueue.ts +56 -0
- package/src/api/queue/getAssignments.ts +19 -0
- package/src/api/queue/listQueues.ts +39 -0
- package/src/api/queue/routeReports.ts +44 -0
- package/src/api/queue/unassignModerator.ts +26 -0
- package/src/api/queue/updateQueue.ts +54 -0
- package/src/api/report/assignModerator.ts +36 -0
- package/src/api/report/createActivity.ts +57 -0
- package/src/api/report/getAssignments.ts +20 -0
- package/src/api/report/getHistoricalStats.ts +41 -0
- package/src/api/report/getLatestReport.ts +44 -0
- package/src/api/report/getLiveStats.ts +26 -0
- package/src/api/report/getReport.ts +55 -0
- package/src/api/report/listActivities.ts +34 -0
- package/src/api/report/queryReports.ts +44 -0
- package/src/api/report/reassignQueue.ts +68 -0
- package/src/api/report/refreshStats.ts +27 -0
- package/src/api/report/unassignModerator.ts +21 -0
- package/src/api/util.ts +12 -0
- package/src/assignment/index.ts +731 -0
- package/src/config/config.ts +27 -0
- package/src/config/env.ts +8 -0
- package/src/context.ts +31 -0
- package/src/daemon/context.ts +34 -0
- package/src/daemon/event-reverser.ts +50 -1
- package/src/daemon/job-cursor.ts +33 -0
- package/src/daemon/queue-router.ts +101 -0
- package/src/daemon/stats-computer.ts +101 -0
- package/src/daemon/strike-expiry-processor.ts +4 -20
- package/src/db/migrations/20260219T164523000Z-create-report-table.ts +155 -0
- package/src/db/migrations/20260219T165302248Z-moderator-assignment.ts +42 -0
- package/src/db/migrations/20260225T000000000Z-add-report-queue-table.ts +41 -0
- package/src/db/migrations/20260313T000000000Z-add-report-activity-table.ts +48 -0
- package/src/db/migrations/20260318T152058935Z-add-report-stat.ts +35 -0
- package/src/db/migrations/20260428T000000000Z-add-expiring-tag-table.ts +32 -0
- package/src/db/migrations/index.ts +6 -0
- package/src/db/pagination.ts +85 -0
- package/src/db/schema/expiring_tag.ts +17 -0
- package/src/db/schema/index.ts +13 -1
- package/src/db/schema/moderator_assignment.ts +16 -0
- package/src/db/schema/report.ts +27 -0
- package/src/db/schema/report_activity.ts +22 -0
- package/src/db/schema/report_queue.ts +21 -0
- package/src/db/schema/report_stat.ts +27 -0
- package/src/lexicon/index.ts +280 -0
- package/src/lexicon/lexicons.ts +2083 -214
- package/src/lexicon/types/app/bsky/embed/external.ts +2 -0
- package/src/lexicon/types/chat/bsky/actor/defs.ts +17 -1
- package/src/lexicon/types/chat/bsky/convo/defs.ts +50 -10
- package/src/lexicon/types/chat/bsky/convo/getMessages.ts +3 -0
- package/src/lexicon/types/tools/ozone/moderation/defs.ts +2 -0
- package/src/lexicon/types/tools/ozone/moderation/emitEvent.ts +24 -0
- package/src/lexicon/types/tools/ozone/queue/assignModerator.ts +46 -0
- package/src/lexicon/types/tools/ozone/queue/createQueue.ts +54 -0
- package/src/lexicon/types/tools/ozone/queue/defs.ts +99 -0
- package/src/lexicon/types/tools/ozone/queue/deleteQueue.ts +48 -0
- package/src/lexicon/types/tools/ozone/queue/getAssignments.ts +48 -0
- package/src/lexicon/types/tools/ozone/queue/listQueues.ts +50 -0
- package/src/lexicon/types/tools/ozone/queue/routeReports.ts +50 -0
- package/src/lexicon/types/tools/ozone/queue/unassignModerator.ts +37 -0
- package/src/lexicon/types/tools/ozone/queue/updateQueue.ts +51 -0
- package/src/lexicon/types/tools/ozone/report/assignModerator.ts +50 -0
- package/src/lexicon/types/tools/ozone/report/createActivity.ts +60 -0
- package/src/lexicon/types/tools/ozone/report/defs.ts +327 -0
- package/src/lexicon/types/tools/ozone/report/getAssignments.ts +48 -0
- package/src/lexicon/types/tools/ozone/report/getHistoricalStats.ts +54 -0
- package/src/lexicon/types/tools/ozone/report/getLatestReport.ts +39 -0
- package/src/lexicon/types/tools/ozone/report/getLiveStats.ts +45 -0
- package/src/lexicon/types/tools/ozone/report/getReport.ts +38 -0
- package/src/lexicon/types/tools/ozone/report/listActivities.ts +44 -0
- package/src/lexicon/types/tools/ozone/report/queryReports.ts +72 -0
- package/src/lexicon/types/tools/ozone/report/reassignQueue.ts +55 -0
- package/src/lexicon/types/tools/ozone/report/refreshStats.ts +46 -0
- package/src/lexicon/types/tools/ozone/report/unassignModerator.ts +44 -0
- package/src/mod-service/expiring-tags.ts +98 -0
- package/src/mod-service/index.ts +71 -3
- package/src/mod-service/report.ts +408 -0
- package/src/queue/service.ts +599 -0
- package/src/report/activity.ts +234 -0
- package/src/report/handle-report-update.ts +209 -0
- package/src/report/reassign.ts +109 -0
- package/src/report/stats.ts +850 -0
- package/src/report/views.ts +241 -0
- package/src/team/index.ts +11 -0
- package/tests/expiring-tags.test.ts +231 -0
- package/tests/get-report.test.ts +136 -0
- package/tests/query-reports.test.ts +608 -0
- package/tests/queue-assignment.test.ts +428 -0
- package/tests/queue-router.test.ts +306 -0
- package/tests/queues.test.ts +690 -0
- package/tests/report-action.test.ts +308 -0
- package/tests/report-activity.test.ts +567 -0
- package/tests/report-assignment.test.ts +517 -0
- package/tests/report-reassign-queue.test.ts +340 -0
- package/tests/report-routing.test.ts +245 -0
- package/tests/report-stats.test.ts +545 -0
- package/tsconfig.build.tsbuildinfo +1 -1
|
@@ -0,0 +1,850 @@
|
|
|
1
|
+
import { Selectable, sql } from 'kysely'
|
|
2
|
+
import { MINUTE } from '@atproto/common'
|
|
3
|
+
import { Database } from '../db'
|
|
4
|
+
import { ComputedAtIdKeyset, paginate } from '../db/pagination'
|
|
5
|
+
import { ReportStat } from '../db/schema/report_stat'
|
|
6
|
+
import { jsonb } from '../db/types'
|
|
7
|
+
import { dbLogger } from '../logger'
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Grouped report types. Stats are computed per group rather than per individual report type.
|
|
11
|
+
*/
|
|
12
|
+
export const REPORT_TYPE_GROUPS: Record<string, string[]> = {
|
|
13
|
+
Legacy: [
|
|
14
|
+
'com.atproto.moderation.defs#reasonSpam',
|
|
15
|
+
'com.atproto.moderation.defs#reasonViolation',
|
|
16
|
+
'com.atproto.moderation.defs#reasonMisleading',
|
|
17
|
+
'com.atproto.moderation.defs#reasonSexual',
|
|
18
|
+
'com.atproto.moderation.defs#reasonRude',
|
|
19
|
+
'com.atproto.moderation.defs#reasonOther',
|
|
20
|
+
'com.atproto.moderation.defs#reasonAppeal',
|
|
21
|
+
],
|
|
22
|
+
Appeal: ['tools.ozone.report.defs#reasonAppeal'],
|
|
23
|
+
Violence: [
|
|
24
|
+
'tools.ozone.report.defs#reasonViolenceAnimalWelfare',
|
|
25
|
+
'tools.ozone.report.defs#reasonViolenceThreats',
|
|
26
|
+
'tools.ozone.report.defs#reasonViolenceGraphicContent',
|
|
27
|
+
'tools.ozone.report.defs#reasonViolenceSelfHarm',
|
|
28
|
+
'tools.ozone.report.defs#reasonViolenceGlorification',
|
|
29
|
+
'tools.ozone.report.defs#reasonViolenceExtremistContent',
|
|
30
|
+
'tools.ozone.report.defs#reasonViolenceTrafficking',
|
|
31
|
+
'tools.ozone.report.defs#reasonViolenceOther',
|
|
32
|
+
],
|
|
33
|
+
Sexual: [
|
|
34
|
+
'tools.ozone.report.defs#reasonSexualAbuseContent',
|
|
35
|
+
'tools.ozone.report.defs#reasonSexualNCII',
|
|
36
|
+
'tools.ozone.report.defs#reasonSexualSextortion',
|
|
37
|
+
'tools.ozone.report.defs#reasonSexualDeepfake',
|
|
38
|
+
'tools.ozone.report.defs#reasonSexualAnimal',
|
|
39
|
+
'tools.ozone.report.defs#reasonSexualUnlabeled',
|
|
40
|
+
'tools.ozone.report.defs#reasonSexualOther',
|
|
41
|
+
],
|
|
42
|
+
'Child Safety': [
|
|
43
|
+
'tools.ozone.report.defs#reasonChildSafetyCSAM',
|
|
44
|
+
'tools.ozone.report.defs#reasonChildSafetyGroom',
|
|
45
|
+
'tools.ozone.report.defs#reasonChildSafetyMinorPrivacy',
|
|
46
|
+
'tools.ozone.report.defs#reasonChildSafetyEndangerment',
|
|
47
|
+
'tools.ozone.report.defs#reasonChildSafetyHarassment',
|
|
48
|
+
'tools.ozone.report.defs#reasonChildSafetyPromotion',
|
|
49
|
+
'tools.ozone.report.defs#reasonChildSafetyOther',
|
|
50
|
+
],
|
|
51
|
+
Harassment: [
|
|
52
|
+
'tools.ozone.report.defs#reasonHarassmentTroll',
|
|
53
|
+
'tools.ozone.report.defs#reasonHarassmentTargeted',
|
|
54
|
+
'tools.ozone.report.defs#reasonHarassmentHateSpeech',
|
|
55
|
+
'tools.ozone.report.defs#reasonHarassmentDoxxing',
|
|
56
|
+
'tools.ozone.report.defs#reasonHarassmentOther',
|
|
57
|
+
],
|
|
58
|
+
Misleading: [
|
|
59
|
+
'tools.ozone.report.defs#reasonMisleadingBot',
|
|
60
|
+
'tools.ozone.report.defs#reasonMisleadingImpersonation',
|
|
61
|
+
'tools.ozone.report.defs#reasonMisleadingSpam',
|
|
62
|
+
'tools.ozone.report.defs#reasonMisleadingScam',
|
|
63
|
+
'tools.ozone.report.defs#reasonMisleadingSyntheticContent',
|
|
64
|
+
'tools.ozone.report.defs#reasonMisleadingMisinformation',
|
|
65
|
+
'tools.ozone.report.defs#reasonMisleadingOther',
|
|
66
|
+
],
|
|
67
|
+
'Rule Violations': [
|
|
68
|
+
'tools.ozone.report.defs#reasonRuleSiteSecurity',
|
|
69
|
+
'tools.ozone.report.defs#reasonRuleStolenContent',
|
|
70
|
+
'tools.ozone.report.defs#reasonRuleProhibitedSales',
|
|
71
|
+
'tools.ozone.report.defs#reasonRuleBanEvasion',
|
|
72
|
+
'tools.ozone.report.defs#reasonRuleOther',
|
|
73
|
+
],
|
|
74
|
+
Civic: [
|
|
75
|
+
'tools.ozone.report.defs#reasonCivicElectoralProcess',
|
|
76
|
+
'tools.ozone.report.defs#reasonCivicDisclosure',
|
|
77
|
+
'tools.ozone.report.defs#reasonCivicInterference',
|
|
78
|
+
'tools.ozone.report.defs#reasonCivicMisinformation',
|
|
79
|
+
'tools.ozone.report.defs#reasonCivicImpersonation',
|
|
80
|
+
],
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const REPORT_STAT_LIVE_TTL = 15 * MINUTE
|
|
84
|
+
|
|
85
|
+
export type ReportStatsServiceCreator = (db: Database) => ReportStatsService
|
|
86
|
+
|
|
87
|
+
export type ReportStatGroup = {
|
|
88
|
+
queueId: number | null
|
|
89
|
+
moderatorDid: string | null
|
|
90
|
+
reportTypes: string[] | null
|
|
91
|
+
}
|
|
92
|
+
export type AggregateStatistics = {
|
|
93
|
+
inboundCount: number
|
|
94
|
+
pendingCount: number
|
|
95
|
+
actionedCount: number
|
|
96
|
+
escalatedCount: number
|
|
97
|
+
actionRate: number
|
|
98
|
+
avgHandlingTimeSec?: number
|
|
99
|
+
}
|
|
100
|
+
export type QueueStatistics = {
|
|
101
|
+
inboundCount: number
|
|
102
|
+
pendingCount: number
|
|
103
|
+
actionedCount: number
|
|
104
|
+
escalatedCount: number
|
|
105
|
+
actionRate: number
|
|
106
|
+
avgHandlingTimeSec?: number
|
|
107
|
+
}
|
|
108
|
+
export type ModeratorStatistics = {
|
|
109
|
+
inboundCount: number
|
|
110
|
+
actionedCount: number
|
|
111
|
+
avgHandlingTimeSec?: number
|
|
112
|
+
}
|
|
113
|
+
export type ReportTypeStatistics = {
|
|
114
|
+
inboundCount: number
|
|
115
|
+
pendingCount: number
|
|
116
|
+
actionedCount: number
|
|
117
|
+
escalatedCount: number
|
|
118
|
+
actionRate: number
|
|
119
|
+
avgHandlingTimeSec?: number
|
|
120
|
+
}
|
|
121
|
+
export type ReportStatistics =
|
|
122
|
+
| QueueStatistics
|
|
123
|
+
| ModeratorStatistics
|
|
124
|
+
| AggregateStatistics
|
|
125
|
+
| ReportTypeStatistics
|
|
126
|
+
|
|
127
|
+
// Batched query result types
|
|
128
|
+
type QueueCountRow = {
|
|
129
|
+
queueId: number | null
|
|
130
|
+
count: string
|
|
131
|
+
}
|
|
132
|
+
type QueueWindowRow = {
|
|
133
|
+
queueId: number | null
|
|
134
|
+
inboundCount: string
|
|
135
|
+
actionedCount: string
|
|
136
|
+
escalatedCount: string
|
|
137
|
+
handlingTimeSum: string | null
|
|
138
|
+
handlingTimeCount: string
|
|
139
|
+
}
|
|
140
|
+
type TypeCountRow = {
|
|
141
|
+
reportType: string
|
|
142
|
+
count: string
|
|
143
|
+
}
|
|
144
|
+
type TypeWindowRow = {
|
|
145
|
+
reportType: string
|
|
146
|
+
inboundCount: string
|
|
147
|
+
actionedCount: string
|
|
148
|
+
escalatedCount: string
|
|
149
|
+
handlingTimeSum: string | null
|
|
150
|
+
handlingTimeCount: string
|
|
151
|
+
}
|
|
152
|
+
type ModeratorWindowRow = {
|
|
153
|
+
did: string
|
|
154
|
+
inboundCount: string
|
|
155
|
+
actionedCount: string
|
|
156
|
+
handlingTimeSum: string | null
|
|
157
|
+
handlingTimeCount: string
|
|
158
|
+
}
|
|
159
|
+
type BatchedStats = {
|
|
160
|
+
queuePending: QueueCountRow[]
|
|
161
|
+
queueWindow: QueueWindowRow[]
|
|
162
|
+
typePending: TypeCountRow[]
|
|
163
|
+
typeWindow: TypeWindowRow[]
|
|
164
|
+
moderator: ModeratorWindowRow[]
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
type UpsertRow = {
|
|
168
|
+
date: string
|
|
169
|
+
queueId: number | null
|
|
170
|
+
moderatorDid: string | null
|
|
171
|
+
reportTypes: string[] | null
|
|
172
|
+
inboundCount: number | null
|
|
173
|
+
pendingCount: number | null
|
|
174
|
+
actionedCount: number | null
|
|
175
|
+
escalatedCount: number | null
|
|
176
|
+
actionRate: number | null
|
|
177
|
+
avgHandlingTimeSec: number | null
|
|
178
|
+
computedAt: string
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
export class ReportStatsService {
|
|
182
|
+
constructor(public db: Database) {}
|
|
183
|
+
|
|
184
|
+
static creator(): ReportStatsServiceCreator {
|
|
185
|
+
return (db: Database) => new ReportStatsService(db)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Compute stats for today and finalize yesterday if needed.
|
|
190
|
+
* Called periodically by the StatsComputer daemon.
|
|
191
|
+
*/
|
|
192
|
+
async materializeAll(opts?: { force?: boolean }): Promise<void> {
|
|
193
|
+
try {
|
|
194
|
+
const start = Date.now()
|
|
195
|
+
const today = toDateString(new Date())
|
|
196
|
+
const yesterday = toDateString(new Date(Date.now() - 24 * 60 * 60 * 1000))
|
|
197
|
+
|
|
198
|
+
// Always compute today's stats
|
|
199
|
+
await this.materializeDate(today, opts)
|
|
200
|
+
|
|
201
|
+
// Finalize yesterday if its snapshot is missing or stale
|
|
202
|
+
if (!opts?.force) {
|
|
203
|
+
const yesterdayRow = await this.db.db
|
|
204
|
+
.selectFrom('report_stat')
|
|
205
|
+
.select('computedAt')
|
|
206
|
+
.where('date', '=', yesterday)
|
|
207
|
+
.orderBy('computedAt', 'desc')
|
|
208
|
+
.executeTakeFirst()
|
|
209
|
+
const endOfYesterday = new Date(`${yesterday}T23:59:59.999Z`).getTime()
|
|
210
|
+
if (
|
|
211
|
+
!yesterdayRow ||
|
|
212
|
+
new Date(yesterdayRow.computedAt).getTime() < endOfYesterday
|
|
213
|
+
) {
|
|
214
|
+
await this.materializeDate(yesterday, { force: true })
|
|
215
|
+
}
|
|
216
|
+
} else {
|
|
217
|
+
await this.materializeDate(yesterday, { force: true })
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
const duration = Date.now() - start
|
|
221
|
+
dbLogger.info({ duration }, 'report stats materialization completed')
|
|
222
|
+
} catch (err) {
|
|
223
|
+
dbLogger.error({ err }, 'report stats materialization errored')
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Compute stats for a specific date range. Used by the refreshStats endpoint.
|
|
229
|
+
*/
|
|
230
|
+
async refreshDateRange(opts: {
|
|
231
|
+
startDate: string
|
|
232
|
+
endDate: string
|
|
233
|
+
queueIds?: number[]
|
|
234
|
+
}): Promise<void> {
|
|
235
|
+
const start = new Date(opts.startDate)
|
|
236
|
+
const end = new Date(opts.endDate)
|
|
237
|
+
|
|
238
|
+
for (let d = new Date(start); d <= end; d.setUTCDate(d.getUTCDate() + 1)) {
|
|
239
|
+
const dateStr = toDateString(d)
|
|
240
|
+
if (opts.queueIds?.length) {
|
|
241
|
+
// Recompute only specific queue groups for this date
|
|
242
|
+
const batched = await this.computeBatchedStats(dateStr)
|
|
243
|
+
const rows: UpsertRow[] = []
|
|
244
|
+
for (const queueId of opts.queueIds) {
|
|
245
|
+
const group: ReportStatGroup = {
|
|
246
|
+
queueId,
|
|
247
|
+
moderatorDid: null,
|
|
248
|
+
reportTypes: null,
|
|
249
|
+
}
|
|
250
|
+
const stats = this.resolveGroupStats(group, batched)
|
|
251
|
+
rows.push(this.buildUpsertRow(dateStr, group, stats))
|
|
252
|
+
}
|
|
253
|
+
await this.bulkUpsert(rows)
|
|
254
|
+
} else {
|
|
255
|
+
await this.materializeDate(dateStr, { force: true })
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/** Compute and write all groups for a single date. */
|
|
261
|
+
private async materializeDate(
|
|
262
|
+
date: string,
|
|
263
|
+
opts?: { force?: boolean },
|
|
264
|
+
): Promise<void> {
|
|
265
|
+
const groups = await this.enumerateGroups()
|
|
266
|
+
const batched = await this.computeBatchedStats(date)
|
|
267
|
+
const today = toDateString(new Date())
|
|
268
|
+
const isToday = date === today
|
|
269
|
+
|
|
270
|
+
// Batch the cache check so we don't issue one SELECT per group.
|
|
271
|
+
const existingByKey = !opts?.force
|
|
272
|
+
? await this.fetchExistingStatsByKey(date)
|
|
273
|
+
: null
|
|
274
|
+
|
|
275
|
+
const rows: UpsertRow[] = []
|
|
276
|
+
for (const group of groups) {
|
|
277
|
+
try {
|
|
278
|
+
if (existingByKey) {
|
|
279
|
+
const cached = existingByKey.get(groupKey(group))
|
|
280
|
+
if (cached) {
|
|
281
|
+
// Historical dates: never recompute. Today: recompute if stale.
|
|
282
|
+
if (!isToday) continue
|
|
283
|
+
const age = Date.now() - new Date(cached.computedAt).getTime()
|
|
284
|
+
if (age < REPORT_STAT_LIVE_TTL) continue
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const stats = this.resolveGroupStats(group, batched)
|
|
288
|
+
rows.push(this.buildUpsertRow(date, group, stats))
|
|
289
|
+
} catch (err) {
|
|
290
|
+
dbLogger.error(
|
|
291
|
+
{ err, group, date },
|
|
292
|
+
'error preparing report stats group',
|
|
293
|
+
)
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
await this.bulkUpsert(rows)
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
/** Fetch all stat rows for a date, keyed by groupKey for O(1) lookup. */
|
|
301
|
+
private async fetchExistingStatsByKey(
|
|
302
|
+
date: string,
|
|
303
|
+
): Promise<Map<string, Selectable<ReportStat>>> {
|
|
304
|
+
const existing = await this.db.db
|
|
305
|
+
.selectFrom('report_stat')
|
|
306
|
+
.selectAll()
|
|
307
|
+
.where('date', '=', date)
|
|
308
|
+
.execute()
|
|
309
|
+
const map = new Map<string, Selectable<ReportStat>>()
|
|
310
|
+
for (const row of existing) {
|
|
311
|
+
map.set(
|
|
312
|
+
groupKey({
|
|
313
|
+
queueId: row.queueId,
|
|
314
|
+
moderatorDid: row.moderatorDid,
|
|
315
|
+
reportTypes: row.reportTypes,
|
|
316
|
+
}),
|
|
317
|
+
row,
|
|
318
|
+
)
|
|
319
|
+
}
|
|
320
|
+
return map
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
/** List out the groups to compute stats for. */
|
|
324
|
+
private async enumerateGroups(): Promise<ReportStatGroup[]> {
|
|
325
|
+
const groups: ReportStatGroup[] = []
|
|
326
|
+
|
|
327
|
+
const queues = await this.db.db
|
|
328
|
+
.selectFrom('report_queue')
|
|
329
|
+
.selectAll()
|
|
330
|
+
.where('enabled', '=', true)
|
|
331
|
+
.where('deletedAt', 'is', null)
|
|
332
|
+
.execute()
|
|
333
|
+
const members = await this.db.db
|
|
334
|
+
.selectFrom('member')
|
|
335
|
+
.select('did')
|
|
336
|
+
.where('disabled', '=', false)
|
|
337
|
+
.where('role', 'in', [
|
|
338
|
+
'tools.ozone.team.defs#roleAdmin',
|
|
339
|
+
'tools.ozone.team.defs#roleModerator',
|
|
340
|
+
'tools.ozone.team.defs#roleTriage',
|
|
341
|
+
])
|
|
342
|
+
.execute()
|
|
343
|
+
|
|
344
|
+
// aggregate
|
|
345
|
+
groups.push({ queueId: null, moderatorDid: null, reportTypes: null })
|
|
346
|
+
// per queue
|
|
347
|
+
for (const queue of queues) {
|
|
348
|
+
groups.push({ queueId: queue.id, moderatorDid: null, reportTypes: null })
|
|
349
|
+
}
|
|
350
|
+
// unqueued
|
|
351
|
+
groups.push({ queueId: -1, moderatorDid: null, reportTypes: null })
|
|
352
|
+
// per moderator
|
|
353
|
+
for (const member of members) {
|
|
354
|
+
groups.push({
|
|
355
|
+
queueId: null,
|
|
356
|
+
moderatorDid: member.did,
|
|
357
|
+
reportTypes: null,
|
|
358
|
+
})
|
|
359
|
+
}
|
|
360
|
+
// per report type group
|
|
361
|
+
for (const groupTypes of Object.values(REPORT_TYPE_GROUPS)) {
|
|
362
|
+
groups.push({
|
|
363
|
+
queueId: null,
|
|
364
|
+
moderatorDid: null,
|
|
365
|
+
reportTypes: groupTypes,
|
|
366
|
+
})
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
return groups
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Run batched GROUP BY queries for a calendar date.
|
|
374
|
+
* Returns 5 result sets covering all group types.
|
|
375
|
+
*/
|
|
376
|
+
private async computeBatchedStats(date: string): Promise<BatchedStats> {
|
|
377
|
+
const dayStart = `${date}T00:00:00.000Z`
|
|
378
|
+
const dayEnd = `${nextDate(date)}T00:00:00.000Z`
|
|
379
|
+
|
|
380
|
+
const [queuePending, aggregatePending] = await Promise.all([
|
|
381
|
+
// Pending count is a snapshot of all non-closed reports at time of computation
|
|
382
|
+
this.db.db
|
|
383
|
+
.selectFrom('report')
|
|
384
|
+
.select(['queueId', sql<string>`count(*)`.as('count')])
|
|
385
|
+
.where('status', '!=', 'closed')
|
|
386
|
+
.where('queueId', 'is not', null)
|
|
387
|
+
.groupBy('queueId')
|
|
388
|
+
.execute(),
|
|
389
|
+
// Aggregate pending (includes all reports, even un-routed)
|
|
390
|
+
this.db.db
|
|
391
|
+
.selectFrom('report')
|
|
392
|
+
.select(sql<string>`count(*)`.as('count'))
|
|
393
|
+
.where('status', '!=', 'closed')
|
|
394
|
+
.executeTakeFirst(),
|
|
395
|
+
])
|
|
396
|
+
|
|
397
|
+
const queueWindow = await this.db.db
|
|
398
|
+
.selectFrom('report')
|
|
399
|
+
.select([
|
|
400
|
+
'queueId',
|
|
401
|
+
sql<string>`count(*)`.as('inboundCount'),
|
|
402
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
403
|
+
'actionedCount',
|
|
404
|
+
),
|
|
405
|
+
sql<string>`count(*) filter (where "status" = 'escalated')`.as(
|
|
406
|
+
'escalatedCount',
|
|
407
|
+
),
|
|
408
|
+
sql<string>`sum(extract(epoch from ("closedAt"::timestamp - "createdAt"::timestamp))) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
409
|
+
'handlingTimeSum',
|
|
410
|
+
),
|
|
411
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
412
|
+
'handlingTimeCount',
|
|
413
|
+
),
|
|
414
|
+
])
|
|
415
|
+
.where('createdAt', '>=', dayStart)
|
|
416
|
+
.where('createdAt', '<', dayEnd)
|
|
417
|
+
.where('queueId', 'is not', null)
|
|
418
|
+
.groupBy('queueId')
|
|
419
|
+
.execute()
|
|
420
|
+
|
|
421
|
+
// Aggregate windowed (includes all reports)
|
|
422
|
+
const aggregateWindow = await this.db.db
|
|
423
|
+
.selectFrom('report')
|
|
424
|
+
.select([
|
|
425
|
+
sql<string>`count(*)`.as('inboundCount'),
|
|
426
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
427
|
+
'actionedCount',
|
|
428
|
+
),
|
|
429
|
+
sql<string>`count(*) filter (where "status" = 'escalated')`.as(
|
|
430
|
+
'escalatedCount',
|
|
431
|
+
),
|
|
432
|
+
sql<string>`sum(extract(epoch from ("closedAt"::timestamp - "createdAt"::timestamp))) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
433
|
+
'handlingTimeSum',
|
|
434
|
+
),
|
|
435
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
436
|
+
'handlingTimeCount',
|
|
437
|
+
),
|
|
438
|
+
])
|
|
439
|
+
.where('createdAt', '>=', dayStart)
|
|
440
|
+
.where('createdAt', '<', dayEnd)
|
|
441
|
+
.executeTakeFirst()
|
|
442
|
+
|
|
443
|
+
const typePending = await this.db.db
|
|
444
|
+
.selectFrom('report')
|
|
445
|
+
.select(['reportType', sql<string>`count(*)`.as('count')])
|
|
446
|
+
.where('status', '!=', 'closed')
|
|
447
|
+
.groupBy('reportType')
|
|
448
|
+
.execute()
|
|
449
|
+
|
|
450
|
+
const typeWindow = await this.db.db
|
|
451
|
+
.selectFrom('report')
|
|
452
|
+
.select([
|
|
453
|
+
'reportType',
|
|
454
|
+
sql<string>`count(*)`.as('inboundCount'),
|
|
455
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
456
|
+
'actionedCount',
|
|
457
|
+
),
|
|
458
|
+
sql<string>`count(*) filter (where "status" = 'escalated')`.as(
|
|
459
|
+
'escalatedCount',
|
|
460
|
+
),
|
|
461
|
+
sql<string>`sum(extract(epoch from ("closedAt"::timestamp - "createdAt"::timestamp))) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
462
|
+
'handlingTimeSum',
|
|
463
|
+
),
|
|
464
|
+
sql<string>`count(*) filter (where "status" = 'closed' and "closedAt" is not null and "closedAt" >= ${dayStart} and "closedAt" < ${dayEnd})`.as(
|
|
465
|
+
'handlingTimeCount',
|
|
466
|
+
),
|
|
467
|
+
])
|
|
468
|
+
.where('createdAt', '>=', dayStart)
|
|
469
|
+
.where('createdAt', '<', dayEnd)
|
|
470
|
+
.groupBy('reportType')
|
|
471
|
+
.execute()
|
|
472
|
+
|
|
473
|
+
const moderator = await this.db.db
|
|
474
|
+
.selectFrom('report as r')
|
|
475
|
+
.innerJoin('moderator_assignment as ma', (join) =>
|
|
476
|
+
join.onRef('ma.reportId', '=', 'r.id').on('ma.endAt', 'is', null),
|
|
477
|
+
)
|
|
478
|
+
.select([
|
|
479
|
+
'ma.did',
|
|
480
|
+
sql<string>`count(*)`.as('inboundCount'),
|
|
481
|
+
sql<string>`count(*) filter (where r."status" = 'closed')`.as(
|
|
482
|
+
'actionedCount',
|
|
483
|
+
),
|
|
484
|
+
sql<string>`sum(extract(epoch from (r."closedAt"::timestamp - ma."startAt"::timestamp))) filter (where r."status" = 'closed' and r."closedAt" is not null)`.as(
|
|
485
|
+
'handlingTimeSum',
|
|
486
|
+
),
|
|
487
|
+
sql<string>`count(*) filter (where r."status" = 'closed' and r."closedAt" is not null)`.as(
|
|
488
|
+
'handlingTimeCount',
|
|
489
|
+
),
|
|
490
|
+
])
|
|
491
|
+
.where('r.createdAt', '>=', dayStart)
|
|
492
|
+
.where('r.createdAt', '<', dayEnd)
|
|
493
|
+
.groupBy('ma.did')
|
|
494
|
+
.execute()
|
|
495
|
+
|
|
496
|
+
// Inject aggregate as a synthetic row with queueId=null so resolveQueueStats can find it
|
|
497
|
+
const allQueuePending: QueueCountRow[] = [
|
|
498
|
+
...queuePending,
|
|
499
|
+
{ queueId: null, count: aggregatePending?.count ?? '0' },
|
|
500
|
+
]
|
|
501
|
+
const allQueueWindow: QueueWindowRow[] = aggregateWindow
|
|
502
|
+
? [
|
|
503
|
+
...queueWindow,
|
|
504
|
+
{
|
|
505
|
+
queueId: null,
|
|
506
|
+
inboundCount: aggregateWindow.inboundCount,
|
|
507
|
+
actionedCount: aggregateWindow.actionedCount,
|
|
508
|
+
escalatedCount: aggregateWindow.escalatedCount,
|
|
509
|
+
handlingTimeSum: aggregateWindow.handlingTimeSum,
|
|
510
|
+
handlingTimeCount: aggregateWindow.handlingTimeCount,
|
|
511
|
+
},
|
|
512
|
+
]
|
|
513
|
+
: queueWindow
|
|
514
|
+
|
|
515
|
+
return {
|
|
516
|
+
queuePending: allQueuePending,
|
|
517
|
+
queueWindow: allQueueWindow,
|
|
518
|
+
typePending,
|
|
519
|
+
typeWindow,
|
|
520
|
+
moderator,
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
/** Resolve a single group's stats from batched query results (pure in-memory). */
|
|
525
|
+
private resolveGroupStats(
|
|
526
|
+
group: ReportStatGroup,
|
|
527
|
+
batched: BatchedStats,
|
|
528
|
+
): ReportStatistics {
|
|
529
|
+
if (group.moderatorDid) {
|
|
530
|
+
return this.resolveModeratorStats(group.moderatorDid, batched.moderator)
|
|
531
|
+
}
|
|
532
|
+
if (group.reportTypes !== null) {
|
|
533
|
+
return this.resolveReportTypeStats(group.reportTypes, batched)
|
|
534
|
+
}
|
|
535
|
+
return this.resolveQueueStats(group.queueId, batched)
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
private resolveQueueStats(
|
|
539
|
+
queueId: number | null,
|
|
540
|
+
batched: BatchedStats,
|
|
541
|
+
): AggregateStatistics | QueueStatistics {
|
|
542
|
+
// queueId=null is the synthetic aggregate row
|
|
543
|
+
const pending = batched.queuePending.find((r) => r.queueId === queueId)
|
|
544
|
+
const window = batched.queueWindow.find((r) => r.queueId === queueId)
|
|
545
|
+
|
|
546
|
+
const pendingCount = num(pending?.count)
|
|
547
|
+
const inboundCount = num(window?.inboundCount)
|
|
548
|
+
const actionedCount = num(window?.actionedCount)
|
|
549
|
+
const escalatedCount = num(window?.escalatedCount)
|
|
550
|
+
const handlingTimeSum = Number(window?.handlingTimeSum ?? 0)
|
|
551
|
+
const handlingTimeCount = num(window?.handlingTimeCount)
|
|
552
|
+
const actionRate =
|
|
553
|
+
inboundCount > 0 ? Math.round((actionedCount / inboundCount) * 100) : 0
|
|
554
|
+
const avgHandlingTimeSec =
|
|
555
|
+
handlingTimeCount > 0
|
|
556
|
+
? Math.round(handlingTimeSum / handlingTimeCount)
|
|
557
|
+
: undefined
|
|
558
|
+
|
|
559
|
+
return {
|
|
560
|
+
inboundCount,
|
|
561
|
+
pendingCount,
|
|
562
|
+
actionedCount,
|
|
563
|
+
escalatedCount,
|
|
564
|
+
actionRate,
|
|
565
|
+
avgHandlingTimeSec,
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
private resolveReportTypeStats(
|
|
570
|
+
reportTypes: string[],
|
|
571
|
+
batched: BatchedStats,
|
|
572
|
+
): ReportTypeStatistics {
|
|
573
|
+
const types = new Set(reportTypes)
|
|
574
|
+
|
|
575
|
+
const matchingPending = batched.typePending.filter((r) =>
|
|
576
|
+
types.has(r.reportType),
|
|
577
|
+
)
|
|
578
|
+
const matchingWindow = batched.typeWindow.filter((r) =>
|
|
579
|
+
types.has(r.reportType),
|
|
580
|
+
)
|
|
581
|
+
|
|
582
|
+
const pendingCount = sumNum(matchingPending, 'count')
|
|
583
|
+
const inboundCount = sumNum(matchingWindow, 'inboundCount')
|
|
584
|
+
const actionedCount = sumNum(matchingWindow, 'actionedCount')
|
|
585
|
+
const escalatedCount = sumNum(matchingWindow, 'escalatedCount')
|
|
586
|
+
const handlingTimeSum = matchingWindow.reduce(
|
|
587
|
+
(sum, r) => sum + Number(r.handlingTimeSum ?? 0),
|
|
588
|
+
0,
|
|
589
|
+
)
|
|
590
|
+
const handlingTimeCount = sumNum(matchingWindow, 'handlingTimeCount')
|
|
591
|
+
|
|
592
|
+
const actionRate =
|
|
593
|
+
inboundCount > 0 ? Math.round((actionedCount / inboundCount) * 100) : 0
|
|
594
|
+
const avgHandlingTimeSec =
|
|
595
|
+
handlingTimeCount > 0
|
|
596
|
+
? Math.round(handlingTimeSum / handlingTimeCount)
|
|
597
|
+
: undefined
|
|
598
|
+
|
|
599
|
+
return {
|
|
600
|
+
inboundCount,
|
|
601
|
+
pendingCount,
|
|
602
|
+
actionedCount,
|
|
603
|
+
escalatedCount,
|
|
604
|
+
actionRate,
|
|
605
|
+
avgHandlingTimeSec,
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
private resolveModeratorStats(
|
|
610
|
+
moderatorDid: string,
|
|
611
|
+
rows: ModeratorWindowRow[],
|
|
612
|
+
): ModeratorStatistics {
|
|
613
|
+
const row = rows.find((r) => r.did === moderatorDid)
|
|
614
|
+
|
|
615
|
+
const inboundCount = num(row?.inboundCount)
|
|
616
|
+
const actionedCount = num(row?.actionedCount)
|
|
617
|
+
const handlingTimeCount = num(row?.handlingTimeCount)
|
|
618
|
+
const avgHandlingTimeSec =
|
|
619
|
+
handlingTimeCount > 0 && row?.handlingTimeSum
|
|
620
|
+
? Math.round(Number(row.handlingTimeSum) / handlingTimeCount)
|
|
621
|
+
: undefined
|
|
622
|
+
|
|
623
|
+
return { inboundCount, actionedCount, avgHandlingTimeSec }
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
/** Build an upsert row from (date, group, stats). */
|
|
627
|
+
private buildUpsertRow(
|
|
628
|
+
date: string,
|
|
629
|
+
group: ReportStatGroup,
|
|
630
|
+
stats: ReportStatistics,
|
|
631
|
+
): UpsertRow {
|
|
632
|
+
const pendingCount =
|
|
633
|
+
'pendingCount' in stats ? stats.pendingCount ?? null : null
|
|
634
|
+
const escalatedCount =
|
|
635
|
+
'escalatedCount' in stats ? stats.escalatedCount ?? null : null
|
|
636
|
+
const actionRate = 'actionRate' in stats ? stats.actionRate ?? null : null
|
|
637
|
+
|
|
638
|
+
return {
|
|
639
|
+
date,
|
|
640
|
+
queueId: group.queueId,
|
|
641
|
+
moderatorDid: group.moderatorDid,
|
|
642
|
+
reportTypes: group.reportTypes,
|
|
643
|
+
inboundCount: stats.inboundCount ?? null,
|
|
644
|
+
pendingCount,
|
|
645
|
+
actionedCount: stats.actionedCount ?? null,
|
|
646
|
+
escalatedCount,
|
|
647
|
+
actionRate,
|
|
648
|
+
avgHandlingTimeSec: stats.avgHandlingTimeSec ?? null,
|
|
649
|
+
computedAt: new Date().toISOString(),
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
/**
|
|
654
|
+
* Wraps a DELETE+INSERT for each row in a single transaction so we pay one
|
|
655
|
+
* commit per cycle instead of one per group. NULL-aware WHERE clauses match
|
|
656
|
+
* the existing PG <15 NULL semantics without needing a unique index.
|
|
657
|
+
*/
|
|
658
|
+
private async bulkUpsert(rows: UpsertRow[]): Promise<void> {
|
|
659
|
+
if (!rows.length) return
|
|
660
|
+
|
|
661
|
+
await this.db.transaction(async (dbTxn) => {
|
|
662
|
+
for (const r of rows) {
|
|
663
|
+
let del = dbTxn.db.deleteFrom('report_stat').where('date', '=', r.date)
|
|
664
|
+
del =
|
|
665
|
+
r.queueId !== null
|
|
666
|
+
? del.where('queueId', '=', r.queueId)
|
|
667
|
+
: del.where('queueId', 'is', null)
|
|
668
|
+
del =
|
|
669
|
+
r.moderatorDid !== null
|
|
670
|
+
? del.where('moderatorDid', '=', r.moderatorDid)
|
|
671
|
+
: del.where('moderatorDid', 'is', null)
|
|
672
|
+
del =
|
|
673
|
+
r.reportTypes !== null
|
|
674
|
+
? del.where(
|
|
675
|
+
sql`"reportTypes"::jsonb = ${jsonb(r.reportTypes)}::jsonb`,
|
|
676
|
+
)
|
|
677
|
+
: del.where('reportTypes', 'is', null)
|
|
678
|
+
await del.execute()
|
|
679
|
+
|
|
680
|
+
await dbTxn.db
|
|
681
|
+
.insertInto('report_stat')
|
|
682
|
+
.values({
|
|
683
|
+
date: r.date,
|
|
684
|
+
queueId: r.queueId,
|
|
685
|
+
moderatorDid: r.moderatorDid,
|
|
686
|
+
reportTypes: r.reportTypes !== null ? jsonb(r.reportTypes) : null,
|
|
687
|
+
inboundCount: r.inboundCount,
|
|
688
|
+
pendingCount: r.pendingCount,
|
|
689
|
+
actionedCount: r.actionedCount,
|
|
690
|
+
escalatedCount: r.escalatedCount,
|
|
691
|
+
actionRate: r.actionRate,
|
|
692
|
+
avgHandlingTimeSec: r.avgHandlingTimeSec,
|
|
693
|
+
computedAt: r.computedAt,
|
|
694
|
+
})
|
|
695
|
+
.execute()
|
|
696
|
+
}
|
|
697
|
+
})
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
// ─── Read methods ───
|
|
701
|
+
|
|
702
|
+
/** Get a single stat row for a date + group. */
|
|
703
|
+
private async getStatForDate(
|
|
704
|
+
date: string,
|
|
705
|
+
group: ReportStatGroup,
|
|
706
|
+
): Promise<Selectable<ReportStat> | undefined> {
|
|
707
|
+
let qb = this.db.db
|
|
708
|
+
.selectFrom('report_stat')
|
|
709
|
+
.selectAll()
|
|
710
|
+
.where('date', '=', date)
|
|
711
|
+
if (group.queueId !== null) {
|
|
712
|
+
qb = qb.where('queueId', '=', group.queueId)
|
|
713
|
+
} else {
|
|
714
|
+
qb = qb.where('queueId', 'is', null)
|
|
715
|
+
}
|
|
716
|
+
if (group.moderatorDid) {
|
|
717
|
+
qb = qb.where('moderatorDid', '=', group.moderatorDid)
|
|
718
|
+
} else {
|
|
719
|
+
qb = qb.where('moderatorDid', 'is', null)
|
|
720
|
+
}
|
|
721
|
+
if (group.reportTypes !== null) {
|
|
722
|
+
qb = qb.where(
|
|
723
|
+
sql`"reportTypes"::jsonb = ${jsonb(group.reportTypes)}::jsonb`,
|
|
724
|
+
)
|
|
725
|
+
} else {
|
|
726
|
+
qb = qb.where('reportTypes', 'is', null)
|
|
727
|
+
}
|
|
728
|
+
return qb.executeTakeFirst()
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/** Get today's live stats for a group. */
|
|
732
|
+
async getLiveStats(
|
|
733
|
+
group: ReportStatGroup,
|
|
734
|
+
): Promise<Selectable<ReportStat> | undefined> {
|
|
735
|
+
const today = toDateString(new Date())
|
|
736
|
+
return this.getStatForDate(today, group)
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
/** Get live stats for multiple queues in a single query. */
|
|
740
|
+
async getLiveStatsForQueues(
|
|
741
|
+
queueIds: number[],
|
|
742
|
+
): Promise<Map<number, Selectable<ReportStat>>> {
|
|
743
|
+
if (!queueIds.length) return new Map()
|
|
744
|
+
|
|
745
|
+
const today = toDateString(new Date())
|
|
746
|
+
const rows = await this.db.db
|
|
747
|
+
.selectFrom('report_stat')
|
|
748
|
+
.selectAll()
|
|
749
|
+
.where('date', '=', today)
|
|
750
|
+
.where('queueId', 'in', queueIds)
|
|
751
|
+
.where('moderatorDid', 'is', null)
|
|
752
|
+
.where('reportTypes', 'is', null)
|
|
753
|
+
.execute()
|
|
754
|
+
|
|
755
|
+
const result = new Map<number, Selectable<ReportStat>>()
|
|
756
|
+
for (const row of rows) {
|
|
757
|
+
if (row.queueId !== null) {
|
|
758
|
+
result.set(row.queueId, row)
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
return result
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
/** Get historical stats for a date range, paginated. */
|
|
765
|
+
async getHistoricalStats(opts: {
|
|
766
|
+
group: ReportStatGroup
|
|
767
|
+
startDate?: string
|
|
768
|
+
endDate?: string
|
|
769
|
+
limit: number
|
|
770
|
+
cursor?: string
|
|
771
|
+
}): Promise<{ stats: Selectable<ReportStat>[]; cursor?: string }> {
|
|
772
|
+
const { group, startDate, endDate, limit } = opts
|
|
773
|
+
const { queueId, moderatorDid, reportTypes } = group
|
|
774
|
+
const { ref } = this.db.db.dynamic
|
|
775
|
+
|
|
776
|
+
let qb = this.db.db.selectFrom('report_stat').selectAll()
|
|
777
|
+
|
|
778
|
+
if (queueId !== null) {
|
|
779
|
+
qb = qb.where('queueId', '=', queueId)
|
|
780
|
+
} else {
|
|
781
|
+
qb = qb.where('queueId', 'is', null)
|
|
782
|
+
}
|
|
783
|
+
if (moderatorDid) {
|
|
784
|
+
qb = qb.where('moderatorDid', '=', moderatorDid)
|
|
785
|
+
} else {
|
|
786
|
+
qb = qb.where('moderatorDid', 'is', null)
|
|
787
|
+
}
|
|
788
|
+
if (reportTypes !== null) {
|
|
789
|
+
qb = qb.where(sql`"reportTypes"::jsonb = ${jsonb(reportTypes)}::jsonb`)
|
|
790
|
+
} else {
|
|
791
|
+
qb = qb.where('reportTypes', 'is', null)
|
|
792
|
+
}
|
|
793
|
+
if (startDate) {
|
|
794
|
+
qb = qb.where('date', '>=', toDateString(new Date(startDate)))
|
|
795
|
+
}
|
|
796
|
+
if (endDate) {
|
|
797
|
+
qb = qb.where('date', '<=', toDateString(new Date(endDate)))
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
const keyset = new ComputedAtIdKeyset(ref('computedAt'), ref('id'))
|
|
801
|
+
const paginatedBuilder = paginate(qb, {
|
|
802
|
+
limit,
|
|
803
|
+
cursor: opts.cursor,
|
|
804
|
+
keyset,
|
|
805
|
+
direction: 'desc',
|
|
806
|
+
tryIndex: true,
|
|
807
|
+
})
|
|
808
|
+
|
|
809
|
+
const stats = await paginatedBuilder.execute()
|
|
810
|
+
|
|
811
|
+
return { stats, cursor: keyset.packFromResult(stats) }
|
|
812
|
+
}
|
|
813
|
+
}
|
|
814
|
+
|
|
815
|
+
// ─── Helpers ───
|
|
816
|
+
|
|
817
|
+
/** Parse a pg bigint string to number, defaulting to 0. */
|
|
818
|
+
function num(val: string | undefined | null): number {
|
|
819
|
+
return val ? Number(val) : 0
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
/** Sum a numeric string field across rows. */
|
|
823
|
+
function sumNum<T>(rows: T[], field: keyof T): number {
|
|
824
|
+
return rows.reduce((sum, r) => sum + Number(r[field] ?? 0), 0)
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
/**
|
|
828
|
+
* Stable cache-key for a stat group. Used to look up an existing row in the
|
|
829
|
+
* batched cache map without issuing per-group SELECTs. Report types are
|
|
830
|
+
* stringified in stored order, which matches REPORT_TYPE_GROUPS.
|
|
831
|
+
*/
|
|
832
|
+
function groupKey(g: ReportStatGroup): string {
|
|
833
|
+
return [
|
|
834
|
+
g.queueId ?? 'null',
|
|
835
|
+
g.moderatorDid ?? 'null',
|
|
836
|
+
g.reportTypes ? JSON.stringify(g.reportTypes) : 'null',
|
|
837
|
+
].join('|')
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
/** Convert a Date to an ISO date string (YYYY-MM-DD). */
|
|
841
|
+
function toDateString(d: Date): string {
|
|
842
|
+
return d.toISOString().slice(0, 10)
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
/** Get the next calendar date string. */
|
|
846
|
+
function nextDate(dateStr: string): string {
|
|
847
|
+
const d = new Date(`${dateStr}T00:00:00.000Z`)
|
|
848
|
+
d.setUTCDate(d.getUTCDate() + 1)
|
|
849
|
+
return toDateString(d)
|
|
850
|
+
}
|