chore: clean up dead barrels, duplicate config, and orphaned frontend components
Gateway: - Remove dead barrels (ai-moderation/index, attachment-upload/index, message-capture/index) — all consumers import files directly - Remove orphaned schema/ split dir (analytics/cache/messages/meta) — schema.ts is monolithic - Merge duplicate config singleton: delete shared/config/config.ts, point all 44 imports at shared/config/index Backend: - Remove dead commandHelper.ts (voice-era fallback), ws/index.ts barrel, health.schema.ts, moderationMetrics.ts, analysis.schema.ts (0 importers; metrics/handlers route directly) Frontend: - Remove orphaned CategoryDrilldown/CoverageTiles/TopicTrends, primitives/slot, use-mobile, use-mounted - Remove unused charts donut/sparkline (TopicTrends was only consumer) Kept (verified active): shared/database/index.ts facade (11 importers), hooks/index + lib/api/index barrels (10 importers), orpc/ws.ts, charts/index.ts barrel. Verified: tsc + biome + vitest per service (backend e2e 3 failures pre-existing on main); frontend next build 8 routes.
This commit is contained in:
1 parent
a59f3132ee
commit
f9fecfc144
63 files changed
+43
-950
No files matched your search
@@ -31,7 +31,7 @@ import { startDigestScheduler } from "../modules/monitor/digestScheduler.js";
|
||||
import { registerReactionCapture } from "../modules/reaction-tracking/index.js";
|
||||
import { registerThreadCapture } from "../modules/thread-tracking/index.js";
|
||||
import { registerPresenceCapture } from "../modules/user-presence/index.js";
|
||||
import { config } from "../shared/config/config.js";
|
||||
import { config } from "../shared/config/index.js";
|
||||
import {
|
||||
closeDatabase,
|
||||
initializeDatabase,
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
NodePgQueryResultHKT,
|
||||
} from "drizzle-orm/node-postgres";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../shared/config/config.js";
|
||||
import { config } from "../shared/config/index.js";
|
||||
import { getDatabase } from "../shared/database/drizzle.js";
|
||||
import type * as schema from "../shared/database/schema.js";
|
||||
import { attachmentsTable, messagesTable } from "../shared/database/schema.js";
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { initializeDatabase } from "../../shared/database/drizzle.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/index.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type { AnalysisQueueStatus } from "../message-capture/types.js";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type {
|
||||
AnalysisResult,
|
||||
MessageRecord,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Guild } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
interface ChannelWithSend {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Client, PermissionString } from "discord.js-selfbot-v13";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { parseRichMessageMetadata } from "../message-capture/messageMetadata.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
const logger = createChildLogger("auto-delete-notify");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { isAgeRestrictedMetadata } from "../message-capture/messageMetadata.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
import {
|
||||
|
||||
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
|
||||
import { availableParallelism } from "node:os";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { Piscina } from "piscina";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { LAST_ERROR } from "./moderationState.js";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { and, desc, eq, sql } from "drizzle-orm";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { getDatabase } from "../../shared/database/drizzle.js";
|
||||
import { messagesTable } from "../../shared/database/schema.js";
|
||||
import { updateChannelCulture } from "./channelCultureStore.js";
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
import OpenAI from "openai";
|
||||
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { cleanContent } from "./textSignals.js";
|
||||
|
||||
const log = createChildLogger("embedding-client");
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
// ── Single-pass LLM pipeline exports ─────────────────────────────────────
|
||||
export type {
|
||||
AnalysisInput,
|
||||
AnalysisResult,
|
||||
MessageBatch,
|
||||
WorkerConfig,
|
||||
} from "./ai-analysis-worker.js";
|
||||
export { startPendingAIAnalysisWorker } from "./aiAnalyzer.js";
|
||||
export { sanitizeDiscordTokens } from "./discordTokens.js";
|
||||
export { runModerationAnalysis } from "./moderationOrchestrator.js";
|
||||
export { buildSystemPrompt } from "./moderationPrompt.js";
|
||||
@@ -1,6 +1,6 @@
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
import type {
|
||||
AnalysisResult,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import type { ChatCompletion } from "openai/resources/chat/completions";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { delay, retryWithBackoff } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { incrementCounterBy } from "../gateway-metrics/index.js";
|
||||
import type { AnalysisResult } from "../message-capture/types.js";
|
||||
import { llmChat } from "./llmClient.js";
|
||||
|
||||
@@ -10,7 +10,7 @@ import OpenAI from "openai";
|
||||
import pLimit from "p-limit";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { retryWithBackoff } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
|
||||
const log = createChildLogger("llm-client");
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* moderationOrchestrator.ts.
|
||||
*/
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type {
|
||||
AnalysisResult,
|
||||
AttachmentRecord,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { incrementCounterBy } from "../gateway-metrics/index.js";
|
||||
import { extractMessageMediaEvidence } from "../message-capture/messageMetadata.js";
|
||||
import type {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { Client } from "discord.js-selfbot-v13";
|
||||
import { LRUCache } from "lru-cache";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/index.js";
|
||||
import type { MessageRecord } from "../message-capture/types.js";
|
||||
import { attemptAutoDeleteFlaggedMessage } from "./autoDeleteManager.js";
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
import { createHash } from "node:crypto";
|
||||
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
|
||||
const log = createChildLogger("qdrant");
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
|
||||
import { uploadToTele } from "../../shared/uploader.js";
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import { LRUCache } from "lru-cache";
|
||||
import pLimit from "p-limit";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { delay } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { cacheGet, cacheSet, makeCacheKey } from "./cacheStore.js";
|
||||
import { escapeXml } from "./moderationBuilders.js";
|
||||
import {
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { delay } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { resizeImageForVision } from "../attachment-upload/imageResizer.js";
|
||||
import type {
|
||||
AnalysisResult,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createHash } from "node:crypto";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { executeAll, executeGet } from "../../shared/database/drizzle.js";
|
||||
import { findBestEmbeddingMatch } from "./embeddingClient.js";
|
||||
import {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { createAbortControllerWithTimeout } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { SearchResult } from "./wikipediaClient.js";
|
||||
|
||||
const log = createChildLogger("tinyfish-search");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { and, desc, eq, sql } from "drizzle-orm";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { getDatabase } from "../../shared/database/drizzle.js";
|
||||
import { messagesTable } from "../../shared/database/schema.js";
|
||||
import { llmChat } from "./llmClient.js";
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
*/
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { delay } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { extractMessageMediaEvidence } from "../message-capture/messageMetadata.js";
|
||||
import type {
|
||||
AttachmentRecord,
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { createAbortControllerWithTimeout } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { cacheGet, cacheSet, makeCacheKey } from "./cacheStore.js";
|
||||
import {
|
||||
cleanContent,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { retryWithBackoff } from "@/shared/utils/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { uploadToTele } from "../../shared/uploader.js";
|
||||
import { messageStore } from "../message-capture/messageStore.js";
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
export { processAttachmentUpload } from "./attachmentUploader.js";
|
||||
export { resizeImageForVision as resizeImage } from "./imageResizer.js";
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client, TextChannel } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
const logger = createChildLogger("channel-topic");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client } from "discord.js-selfbot-v13";
|
||||
import Redis from "ioredis";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import {
|
||||
BACKEND_COMMAND,
|
||||
type CommandMessage,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import http from "node:http";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
|
||||
const logger = createChildLogger("gateway-metrics");
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import type {
|
||||
PartialGuildMember,
|
||||
} from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
const logger = createChildLogger("guild-member-events");
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
upsertQdrantPointV2,
|
||||
} from "@/modules/ai-moderation/qdrantClient";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
|
||||
const log = createChildLogger("archive-embedder");
|
||||
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
export {
|
||||
getDisplayContent,
|
||||
getMessageLocation,
|
||||
getMessageMetadata,
|
||||
} from "../message-capture/messageMetadata.js";
|
||||
export type {
|
||||
AIRecommendedAction,
|
||||
AISeverity,
|
||||
AIStatus,
|
||||
AttachmentRecord,
|
||||
MessageRecord,
|
||||
} from "../message-capture/types.js";
|
||||
export type { TextCaptureTarget } from "./messageCapture.js";
|
||||
export {
|
||||
captureMessage,
|
||||
registerMessageCapture,
|
||||
setEventBroadcaster,
|
||||
} from "./messageCapture.js";
|
||||
export { messageStore } from "./messageStore.js";
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client, Message } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { queueMessageAnalysis } from "../ai-moderation/aiAnalyzer.js";
|
||||
import { processAttachmentUpload } from "../attachment-upload/attachmentUploader.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
@@ -6,7 +6,7 @@ import type {
|
||||
User,
|
||||
} from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import { getDatabase } from "../../shared/database/drizzle.js";
|
||||
import { reactionsTable } from "../../shared/database/schema.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client, ThreadChannel } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
const logger = createChildLogger("thread-tracking");
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { Client, Presence } from "discord.js-selfbot-v13";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import type { EventBroadcaster } from "../event-broadcaster/eventBroadcaster.js";
|
||||
|
||||
const logger = createChildLogger("presence-tracking");
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import "dotenv/config";
|
||||
import type { AppConfig } from "@/shared/config/index";
|
||||
import { loadConfig as sharedLoadConfig } from "@/shared/config/index";
|
||||
|
||||
// Re-export the unified config — all EFFECTIVE_* fields are already
|
||||
// computed by the shared loadConfig().
|
||||
export type { AppConfig };
|
||||
|
||||
export function loadConfig(env: NodeJS.ProcessEnv = process.env): AppConfig {
|
||||
return sharedLoadConfig(env);
|
||||
}
|
||||
|
||||
export const config = loadConfig();
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
withDatabaseClient as sharedWithClient,
|
||||
} from "@/shared/database/init";
|
||||
import { createChildLogger } from "@/shared/logger/index";
|
||||
import { config } from "../../shared/config/config.js";
|
||||
import { config } from "../../shared/config/index.js";
|
||||
import * as schema from "./schema.js";
|
||||
|
||||
const logger = createChildLogger("drizzle");
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
import {
|
||||
pgAIAnalysisRunsTable,
|
||||
pgChannelCulturesTable,
|
||||
pgUserProfilesTable,
|
||||
} from "../../../shared/index.js";
|
||||
|
||||
// Re-export shared tables
|
||||
export { pgAIAnalysisRunsTable, pgChannelCulturesTable, pgUserProfilesTable };
|
||||
export const aiAnalysisRunsTable = pgAIAnalysisRunsTable;
|
||||
export const channelCulturesTable = pgChannelCulturesTable;
|
||||
export const userProfilesTable = pgUserProfilesTable;
|
||||
|
||||
// Types
|
||||
export type AIAnalysisRun = typeof aiAnalysisRunsTable.$inferSelect;
|
||||
export type AIAnalysisRunInsert = typeof aiAnalysisRunsTable.$inferInsert;
|
||||
export type ChannelCulture = typeof channelCulturesTable.$inferSelect;
|
||||
export type ChannelCultureInsert = typeof channelCulturesTable.$inferInsert;
|
||||
export type UserProfile = typeof userProfilesTable.$inferSelect;
|
||||
export type UserProfileInsert = typeof userProfilesTable.$inferInsert;
|
||||
@@ -1,22 +0,0 @@
|
||||
import {
|
||||
pgCorrectedModerationsTable,
|
||||
pgStickerCacheTable,
|
||||
pgTextAnalysisCacheTable,
|
||||
} from "../../../shared/index.js";
|
||||
|
||||
// Re-export shared tables
|
||||
export {
|
||||
pgCorrectedModerationsTable,
|
||||
pgStickerCacheTable,
|
||||
pgTextAnalysisCacheTable,
|
||||
};
|
||||
export const correctedModerationsTable = pgCorrectedModerationsTable;
|
||||
export const stickerCacheTable = pgStickerCacheTable;
|
||||
export const textAnalysisCacheTable = pgTextAnalysisCacheTable;
|
||||
|
||||
// Types
|
||||
export type StickerCacheRecord = typeof stickerCacheTable.$inferSelect;
|
||||
export type StickerCacheInsert = typeof stickerCacheTable.$inferInsert;
|
||||
export type CorrectedModeration = typeof correctedModerationsTable.$inferSelect;
|
||||
export type CorrectedModerationInsert =
|
||||
typeof correctedModerationsTable.$inferInsert;
|
||||
@@ -1,140 +0,0 @@
|
||||
import {
|
||||
bigint as pgBigint,
|
||||
boolean as pgBoolean,
|
||||
index as pgIndex,
|
||||
real as pgReal,
|
||||
pgTable,
|
||||
text as pgText,
|
||||
uuid as pgUuid,
|
||||
} from "drizzle-orm/pg-core";
|
||||
import {
|
||||
pgAttachmentsTable,
|
||||
pgMessageReviewsTable,
|
||||
pgMessagesTable,
|
||||
} from "../../../shared/index.js";
|
||||
|
||||
// Re-export shared message/attachment/review tables
|
||||
export { pgAttachmentsTable, pgMessageReviewsTable, pgMessagesTable };
|
||||
export const messagesTable = pgMessagesTable;
|
||||
export const attachmentsTable = pgAttachmentsTable;
|
||||
export const messageReviewsTable = pgMessageReviewsTable;
|
||||
|
||||
/**
|
||||
* Moderation Actions Table (PostgreSQL)
|
||||
* Tracks actions taken on messages (delete, mute, etc.)
|
||||
*/
|
||||
export const pgModerationActionsTable = pgTable(
|
||||
"moderation_actions",
|
||||
{
|
||||
id: pgText("id").primaryKey(),
|
||||
message_id: pgText("message_id"),
|
||||
user_id: pgText("user_id"),
|
||||
guild_id: pgText("guild_id").notNull(),
|
||||
action_type: pgText("action_type", {
|
||||
enum: [
|
||||
"delete_message",
|
||||
"mute_user",
|
||||
"warn_user",
|
||||
"kick_user",
|
||||
"ban_user",
|
||||
],
|
||||
}).notNull(),
|
||||
reason: pgText("reason"),
|
||||
executed_by: pgText("executed_by"),
|
||||
status: pgText("status", {
|
||||
enum: ["pending", "executed", "failed"],
|
||||
})
|
||||
.notNull()
|
||||
.default("pending"),
|
||||
error: pgText("error"),
|
||||
created_at: pgBigint("created_at", { mode: "number" }).notNull(),
|
||||
executed_at: pgBigint("executed_at", { mode: "number" }),
|
||||
// ── Explainability (structured verdict; surfaced read-only to public web) ──
|
||||
flags: pgText("flags"), // JSON array of string flags, e.g. ["sara_agama","vulgar"]
|
||||
categories: pgText("categories"), // JSON array of category strings
|
||||
severity: pgText("severity", {
|
||||
enum: ["none", "low", "medium", "high", "critical"],
|
||||
}),
|
||||
confidence: pgReal("confidence"), // 0..1
|
||||
score: pgReal("score"), // 0..1 raw model score
|
||||
evidence: pgText("evidence"), // JSON array of short quoted snippets
|
||||
policy_version: pgText("policy_version"), // rules.ts policy version string
|
||||
username: pgText("username"), // denormalized from messages table for retention safety
|
||||
server_nick: pgText("server_nick"), // member's server-specific display name (nickname), from metadata.member.displayName
|
||||
},
|
||||
(table) => ({
|
||||
messageIdIdx: pgIndex("idx_moderation_actions_message_id").on(
|
||||
table.message_id,
|
||||
),
|
||||
userIdIdx: pgIndex("idx_moderation_actions_user_id").on(table.user_id),
|
||||
statusIdx: pgIndex("idx_moderation_actions_status").on(table.status),
|
||||
guildStatusIdx: pgIndex("idx_moderation_actions_guild_status").on(
|
||||
table.guild_id,
|
||||
table.status,
|
||||
table.created_at,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
export const moderationActionsTable = pgModerationActionsTable;
|
||||
|
||||
/**
|
||||
* Message Edits Table (PostgreSQL)
|
||||
*/
|
||||
export const pgMessageEditsTable = pgTable(
|
||||
"message_edits",
|
||||
{
|
||||
id: pgUuid("id").defaultRandom().primaryKey(),
|
||||
message_id: pgText("message_id").notNull(),
|
||||
old_content: pgText("old_content").notNull(),
|
||||
edited_at: pgBigint("edited_at", { mode: "number" }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
messageIdIdx: pgIndex("idx_message_edits_message_id").on(table.message_id),
|
||||
editedAtIdx: pgIndex("idx_message_edits_edited_at").on(table.edited_at),
|
||||
}),
|
||||
);
|
||||
|
||||
export const messageEditsTable = pgMessageEditsTable;
|
||||
|
||||
/**
|
||||
* Reactions Table (PostgreSQL)
|
||||
*/
|
||||
export const pgReactionsTable = pgTable(
|
||||
"message_reactions",
|
||||
{
|
||||
id: pgText("id").primaryKey(),
|
||||
message_id: pgText("message_id").notNull(),
|
||||
channel_id: pgText("channel_id").notNull(),
|
||||
guild_id: pgText("guild_id").notNull(),
|
||||
user_id: pgText("user_id").notNull(),
|
||||
username: pgText("username").notNull(),
|
||||
emoji: pgText("emoji").notNull(),
|
||||
emoji_id: pgText("emoji_id"),
|
||||
animated: pgBoolean("animated").notNull().default(false),
|
||||
reaction_type: pgText("reaction_type", {
|
||||
enum: ["add", "remove"],
|
||||
}).notNull(),
|
||||
created_at: pgBigint("created_at", { mode: "number" }).notNull(),
|
||||
},
|
||||
(table) => ({
|
||||
messageIdIdx: pgIndex("idx_reactions_message_id").on(table.message_id),
|
||||
userIdIdx: pgIndex("idx_reactions_user_id").on(table.user_id),
|
||||
guildCreatedIdx: pgIndex("idx_reactions_guild_created").on(
|
||||
table.guild_id,
|
||||
table.created_at,
|
||||
),
|
||||
}),
|
||||
);
|
||||
|
||||
export const reactionsTable = pgReactionsTable;
|
||||
|
||||
// Types
|
||||
export type Message = typeof messagesTable.$inferSelect;
|
||||
export type MessageInsert = typeof messagesTable.$inferInsert;
|
||||
export type Attachment = typeof attachmentsTable.$inferSelect;
|
||||
export type AttachmentInsert = typeof attachmentsTable.$inferInsert;
|
||||
export type MessageReview = typeof messageReviewsTable.$inferSelect;
|
||||
export type MessageReviewInsert = typeof messageReviewsTable.$inferInsert;
|
||||
export type ModerationAction = typeof moderationActionsTable.$inferSelect;
|
||||
export type ModerationActionInsert = typeof moderationActionsTable.$inferInsert;
|
||||
@@ -1,28 +0,0 @@
|
||||
import {
|
||||
pgChatbotMessagesTable,
|
||||
pgMuxerJobsTable,
|
||||
pgRetentionPoliciesTable,
|
||||
pgUIStateTable,
|
||||
} from "../../../shared/index.js";
|
||||
|
||||
// Re-export shared tables
|
||||
export {
|
||||
pgChatbotMessagesTable,
|
||||
pgMuxerJobsTable,
|
||||
pgRetentionPoliciesTable,
|
||||
pgUIStateTable,
|
||||
};
|
||||
export const muxerJobsTable = pgMuxerJobsTable;
|
||||
export const uiStateTable = pgUIStateTable;
|
||||
export const retentionPoliciesTable = pgRetentionPoliciesTable;
|
||||
export const chatbotMessagesTable = pgChatbotMessagesTable;
|
||||
|
||||
// Types
|
||||
export type MuxerJob = typeof muxerJobsTable.$inferSelect;
|
||||
export type MuxerJobInsert = typeof muxerJobsTable.$inferInsert;
|
||||
export type UIState = typeof uiStateTable.$inferSelect;
|
||||
export type UIStateInsert = typeof uiStateTable.$inferInsert;
|
||||
export type RetentionPolicy = typeof retentionPoliciesTable.$inferSelect;
|
||||
export type RetentionPolicyInsert = typeof retentionPoliciesTable.$inferInsert;
|
||||
export type ChatbotMessage = typeof chatbotMessagesTable.$inferSelect;
|
||||
export type ChatbotMessageInsert = typeof chatbotMessagesTable.$inferInsert;
|
||||
Reference in new issue
Block a user