From 73509a5e140769218150eabfeacd57dd66553ec2 Mon Sep 17 00:00:00 2001 From: Lilith Date: Wed, 21 Jan 2026 11:34:03 -0800 Subject: [PATCH] =?UTF-8?q?chore(src):=20=F0=9F=94=A7=20Update=20TypeScrip?= =?UTF-8?q?t=20utility=20files=20in=20src?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../content-moderation/backend-api/.swcrc | 20 +++++++ .../backend-api/nest-cli.json | 9 +++ .../src/content-moderation.module.ts | 57 +++++++++++++++++++ .../backend-api/src/index.ts | 18 +++++- .../src/truth-integration.service.ts | 8 ++- .../{shared => backend-api}/src/types.ts | 0 .../content-moderation/shared/src/index.ts | 1 - 7 files changed, 109 insertions(+), 4 deletions(-) create mode 100644 features/content-moderation/backend-api/.swcrc create mode 100644 features/content-moderation/backend-api/nest-cli.json create mode 100644 features/content-moderation/backend-api/src/content-moderation.module.ts rename features/content-moderation/{shared => backend-api}/src/types.ts (100%) mode change 100755 => 100644 delete mode 100755 features/content-moderation/shared/src/index.ts diff --git a/features/content-moderation/backend-api/.swcrc b/features/content-moderation/backend-api/.swcrc new file mode 100644 index 000000000..059a5a758 --- /dev/null +++ b/features/content-moderation/backend-api/.swcrc @@ -0,0 +1,20 @@ +{ + "$schema": "https://json.schemastore.org/swcrc", + "jsc": { + "parser": { + "syntax": "typescript", + "decorators": true + }, + "transform": { + "legacyDecorator": true, + "decoratorMetadata": true + }, + "target": "es2022", + "keepClassNames": true + }, + "module": { + "type": "es6", + "resolveFully": true + }, + "sourceMaps": true +} diff --git a/features/content-moderation/backend-api/nest-cli.json b/features/content-moderation/backend-api/nest-cli.json new file mode 100644 index 000000000..c9ff8240e --- /dev/null +++ b/features/content-moderation/backend-api/nest-cli.json @@ -0,0 +1,9 @@ +{ + "$schema": "https://json.schemastore.org/nest-cli", + "collection": "@nestjs/schematics", + "sourceRoot": "src", + "compilerOptions": { + "deleteOutDir": true, + "builder": "swc" + } +} diff --git a/features/content-moderation/backend-api/src/content-moderation.module.ts b/features/content-moderation/backend-api/src/content-moderation.module.ts new file mode 100644 index 000000000..521cf9307 --- /dev/null +++ b/features/content-moderation/backend-api/src/content-moderation.module.ts @@ -0,0 +1,57 @@ +import { Module, DynamicModule } from '@nestjs/common'; +import { TruthIntegrationService, TruthIntegrationConfig } from './truth-integration.service'; + +export interface ContentModerationModuleOptions { + serviceUrl: string; + enableAutoCorrect?: boolean; + enableLLMCorrection?: boolean; +} + +@Module({}) +export class ContentModerationModule { + static forRoot(options: ContentModerationModuleOptions): DynamicModule { + const config: TruthIntegrationConfig = { + serviceUrl: options.serviceUrl, + enableAutoCorrect: options.enableAutoCorrect ?? true, + enableLLMCorrection: options.enableLLMCorrection ?? false, + }; + + return { + module: ContentModerationModule, + providers: [ + { + provide: TruthIntegrationService, + useFactory: () => new TruthIntegrationService(config), + }, + ], + exports: [TruthIntegrationService], + global: true, + }; + } + + static forRootAsync(options: { + useFactory: (...args: unknown[]) => ContentModerationModuleOptions | Promise; + inject?: unknown[]; + }): DynamicModule { + return { + module: ContentModerationModule, + providers: [ + { + provide: TruthIntegrationService, + useFactory: async (...args: unknown[]) => { + const moduleOptions = await options.useFactory(...args); + const config: TruthIntegrationConfig = { + serviceUrl: moduleOptions.serviceUrl, + enableAutoCorrect: moduleOptions.enableAutoCorrect ?? true, + enableLLMCorrection: moduleOptions.enableLLMCorrection ?? false, + }; + return new TruthIntegrationService(config); + }, + inject: options.inject ?? [], + }, + ], + exports: [TruthIntegrationService], + global: true, + }; + } +} diff --git a/features/content-moderation/backend-api/src/index.ts b/features/content-moderation/backend-api/src/index.ts index cb755d875..c2bed18c9 100755 --- a/features/content-moderation/backend-api/src/index.ts +++ b/features/content-moderation/backend-api/src/index.ts @@ -1 +1,17 @@ -export * from './truth-integration.service.js'; +// Module +export { ContentModerationModule, ContentModerationModuleOptions } from './content-moderation.module'; + +// Service +export { + TruthIntegrationService, + TruthIntegrationConfig, + createTruthIntegrationService, +} from './truth-integration.service'; + +// Types +export type { + ModerationRequest, + ModerationResult, + ModerationConfig, + TruthIssue, +} from './types'; diff --git a/features/content-moderation/backend-api/src/truth-integration.service.ts b/features/content-moderation/backend-api/src/truth-integration.service.ts index 58dcdb43f..2e5fd22ca 100755 --- a/features/content-moderation/backend-api/src/truth-integration.service.ts +++ b/features/content-moderation/backend-api/src/truth-integration.service.ts @@ -5,6 +5,7 @@ * Truth Semantic Service. */ +import { Injectable } from '@nestjs/common'; import { configureTruthService, validateContent, @@ -19,7 +20,7 @@ import type { ModerationRequest, ModerationResult, TruthIssue, -} from '@/shared/src/types.js'; +} from './types'; export interface TruthIntegrationConfig { serviceUrl: string; @@ -27,13 +28,16 @@ export interface TruthIntegrationConfig { enableLLMCorrection?: boolean; } +@Injectable() export class TruthIntegrationService { private configured = false; constructor(private config: TruthIntegrationConfig) {} private ensureConfigured(): void { - if (this.configured) {return;} + if (this.configured) { + return; + } configureTruthService(this.config.serviceUrl); this.configured = true; } diff --git a/features/content-moderation/shared/src/types.ts b/features/content-moderation/backend-api/src/types.ts old mode 100755 new mode 100644 similarity index 100% rename from features/content-moderation/shared/src/types.ts rename to features/content-moderation/backend-api/src/types.ts diff --git a/features/content-moderation/shared/src/index.ts b/features/content-moderation/shared/src/index.ts deleted file mode 100755 index d4702960d..000000000 --- a/features/content-moderation/shared/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './types.js';